0021189: Clean up KAS:dev:ros and Products
authorvro <vro@opencascade.com>
Fri, 5 Oct 2012 10:17:17 +0000 (14:17 +0400)
committervro <vro@opencascade.com>
Fri, 5 Oct 2012 10:17:17 +0000 (14:17 +0400)
Removal of VoxelClient
VoxelDemo sample is redesigned so that it doesn't require compilation of OpenGl classes. It refers to TKOpenGl.dll as to an external library.
Some minor bugs are fixed in OCAF and Viewer 3d standard MFC samples

38 files changed:
adm/UDLIST
samples/mfc/standard/04_Viewer3d/src/Viewer3dView.cpp
samples/mfc/standard/06_Ocaf/src/OcafApp.cpp
samples/mfc/standard/06_Ocaf/src/OcafDoc.cpp
samples/qt/VoxelDemo/VoxelDemo.sln [new file with mode: 0644]
samples/qt/VoxelDemo/VoxelDemo.vcproj [new file with mode: 0644]
samples/qt/VoxelDemo/inc/Application.h [new file with mode: 0644]
samples/qt/VoxelDemo/inc/ConversionThread.h [new file with mode: 0644]
samples/qt/VoxelDemo/inc/Timer.h [new file with mode: 0644]
samples/qt/VoxelDemo/inc/Viewer.h [new file with mode: 0644]
samples/qt/VoxelDemo/inc/VoxelClient_VisDrawer.h [new file with mode: 0644]
samples/qt/VoxelDemo/msvc.bat [new file with mode: 0644]
samples/qt/VoxelDemo/src/Application.cpp [new file with mode: 0644]
samples/qt/VoxelDemo/src/ConversionThread.cpp [new file with mode: 0644]
samples/qt/VoxelDemo/src/Main.cpp [new file with mode: 0644]
samples/qt/VoxelDemo/src/Timer.cpp [new file with mode: 0644]
samples/qt/VoxelDemo/src/Viewer.cpp [new file with mode: 0644]
samples/qt/VoxelDemo/src/VoxelClient_VisDrawer.cxx [new file with mode: 0644]
samples/qt/voxeldemo/OpenGl/OpenGl.vcproj [deleted file]
samples/qt/voxeldemo/VoxelDemo-vc8.sln [deleted file]
samples/qt/voxeldemo/VoxelDemo-vc9.sln [deleted file]
samples/qt/voxeldemo/VoxelDemo.vcproj [deleted file]
samples/qt/voxeldemo/env.bat [deleted file]
samples/qt/voxeldemo/inc/Application.h [deleted file]
samples/qt/voxeldemo/inc/ConversionThread.h [deleted file]
samples/qt/voxeldemo/inc/Timer.h [deleted file]
samples/qt/voxeldemo/inc/Viewer.h [deleted file]
samples/qt/voxeldemo/msvc.bat [deleted file]
samples/qt/voxeldemo/run.bat [deleted file]
samples/qt/voxeldemo/src/Application.cpp [deleted file]
samples/qt/voxeldemo/src/ConversionThread.cpp [deleted file]
samples/qt/voxeldemo/src/Main.cpp [deleted file]
samples/qt/voxeldemo/src/Timer.cpp [deleted file]
samples/qt/voxeldemo/src/Viewer.cpp [deleted file]
src/OS/Visualization.tcl
src/VoxelClient/FILES [deleted file]
src/VoxelClient/VoxelClient_VisDrawer.cxx [deleted file]
src/VoxelClient/VoxelClient_VisDrawer.h [deleted file]

index 2165d54..c2f073c 100644 (file)
@@ -207,7 +207,6 @@ t TKShHealing
 t TKTopAlgo
 t TKXMesh
 n InterfaceGraphic
-n VoxelClient
 p AIS
 p AIS2D
 p AlienImage
index 70da435..d04a262 100755 (executable)
@@ -1088,11 +1088,30 @@ GetDocument()->UpdateResultMessageDlg("SetAntialiasingOn/SetAntialiasingOff",Mes
 void CViewer3dView::OnClearLights() 
 {
 //     Setting Off all viewer active lights
+    TColStd_ListOfTransient lights;
        for(myView->Viewer()->InitActiveLights(); myView->Viewer()->MoreActiveLights(); myView->Viewer()->NextActiveLights())
-               myView->Viewer()->SetLightOff(myView->Viewer()->ActiveLight());
+    {
+        lights.Append(myView->Viewer()->ActiveLight());
+    }
+    TColStd_ListIteratorOfListOfTransient itrLights(lights);
+    for (; itrLights.More(); itrLights.Next())
+    {
+        Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());
+        myView->Viewer()->SetLightOff(light);
+    }
+
 //     Setting Off all view active lights
-       for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights())
-               myView->SetLightOff(myView->ActiveLight());
+    lights.Clear();
+    for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights())
+    {
+        lights.Append(myView->ActiveLight());
+    }
+    itrLights.Initialize(lights);
+    for (; itrLights.More(); itrLights.Next())
+    {
+        Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());
+        myView->SetLightOff(light);
+    }
 
        myView->Viewer()->SetDefaultLights();// Setting the default lights on
 
@@ -1101,10 +1120,31 @@ void CViewer3dView::OnClearLights()
        myView->Update();
 
 TCollection_AsciiString Message("\
+//     Setting Off all viewer active lights\n\
+TColStd_ListOfTransient lights;\n\
 for(myView->Viewer()->InitActiveLights(); myView->Viewer()->MoreActiveLights(); myView->Viewer()->NextActiveLights())\n\
-       myView->Viewer()->SetLightOff(myView->Viewer()->ActiveLight()); //Setting Off all viewer active lights\n\
+{\n\
+    lights.Append(myView->Viewer()->ActiveLight());\n\
+}\n\
+TColStd_ListIteratorOfListOfTransient itrLights(lights);\n\
+for (; itrLights.More(); itrLights.Next())\n\
+{\n\
+    Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());\n\
+    myView->Viewer()->SetLightOff(light);\n\
+}\n\
+\n\
+//     Setting Off all view active lights\n\
+lights.Clear();\n\
 for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights())\n\
-       myView->SetLightOff(myView->ActiveLight()); //Setting Off all view active lights\n\
+{\n\
+    lights.Append(myView->ActiveLight());\n\
+}\n\
+itrLights.Initialize(lights);\n\
+for (; itrLights.More(); itrLights.Next())\n\
+{\n\
+    Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());\n\
+    myView->SetLightOff(light);\n\
+}\n\
 \n\
 myView->Viewer()->SetDefaultLights();// Setting the default lights on\n\
   ");
index ed5d3a8..6a106f5 100755 (executable)
@@ -143,7 +143,7 @@ BOOL COcafApp::IsViewExisting(CDocument * pDoc, CRuntimeClass * pViewClass, CVie
 void COcafApp::OnFileOpen() 
 {
        CFileDialog aDlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,
-          "OCAFSample(STA) (*.sta)|*.sta|OCAFSample(XML) (*.xml)|*.xml|OCAFSample(Binary) (*.cbf)|*.cbf||");
+          "OCAFSample(STD) (*.std)|*.std|OCAFSample(XML) (*.xml)|*.xml|OCAFSample(Binary) (*.cbf)|*.cbf||");
 
        if (aDlg.DoModal() != IDOK) 
         return;
index 75234c6..329dff7 100755 (executable)
@@ -603,7 +603,8 @@ D->CommitCommand(); \n\
 
                // Get the TOcafFunction_CutDriver using its Standard_GUID in the TFunction_DriverTable
                Handle(TOcafFunction_CutDriver) myCutDriver;
-               TFunction_DriverTable::Get()->FindDriver(myDriverID, myCutDriver);
+               if (TFunction_DriverTable::Get()->FindDriver(myDriverID, myCutDriver))
+            myCutDriver->Init(LabObject);
 
                // Recompute the cut object if it must be (look at the MustExecute function code)
 //             if (myCutDriver->MustExecute(log))
@@ -904,21 +905,21 @@ void COcafDoc::OnFileSaveAs()
        CString Filter;
 
        if (TPathName.SearchFromEnd(".xml") > 0){
-               Filter = "OCAFSample(XML) (*.xml)|*.xml|OCAFSample(STA) (*.sta)|*.sta|OCAFSample(Binary) (*.cbf)|*.cbf||";
+               Filter = "OCAFSample(XML) (*.xml)|*.xml|OCAFSample(STD) (*.std)|*.std|OCAFSample(Binary) (*.cbf)|*.cbf||";
        }
        else if (TPathName.SearchFromEnd(".cbf") > 0){
-               Filter = "OCAFSample(Binary) (*.cbf)|*.cbf|OCAFSample(STA) (*.sta)|*.sta|OCAFSample(XML) (*.xml)|*.xml||";
+               Filter = "OCAFSample(Binary) (*.cbf)|*.cbf|OCAFSample(STD) (*.std)|*.std|OCAFSample(XML) (*.xml)|*.xml||";
        }
        else{
-               Filter = "OCAFSample(STA) (*.sta)|*.sta|OCAFSample(XML) (*.xml)|*.xml|OCAFSample(Binary) (*.cbf)|*.cbf||";
+               Filter = "OCAFSample(STD) (*.std)|*.std|OCAFSample(XML) (*.xml)|*.xml|OCAFSample(Binary) (*.cbf)|*.cbf||";
        }
        
        CFileDialog dlg(FALSE,
-                       "sta",
+                       "std",
                        GetTitle(),
                        OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
                        Filter,
-//                     "sta Files (*.sta)|*.sta; |All Files (*.*)|*.*||", 
+//                     "std Files (*.std)|*.std; |All Files (*.*)|*.*||", 
                        NULL );
        
 
@@ -930,8 +931,8 @@ void COcafDoc::OnFileSaveAs()
        CWaitCursor aWaitCursor;
        CString CSPath = dlg.GetPathName();
 
-//     if((CSPath.Find(CString(".sta")))==-1 )
-//             CSPath = CSPath + ".sta";
+//     if((CSPath.Find(CString(".std")))==-1 )
+//             CSPath = CSPath + ".std";
 
        cout << "Save As " << CSPath << endl;
        PathName=CSPath;
@@ -1042,11 +1043,11 @@ m_App->SaveAs(myOcafDoc,(TCollection_ExtendedString) TPath); \n\
        }
 
        CFileDialog dlg(FALSE,
-                       "sta",
+                       "std",
                        GetTitle(),
                        OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
-                       "OCAFSample(STA) (*.sta)|*.sta|OCAFSample(XML) (*.xml)|*.xml|OCAFSample(Binary) (*.cbf)|*.cbf||",
-//                     "sta Files (*.sta)|*.sta; |All Files (*.*)|*.*||", 
+                       "OCAFSample(STD) (*.std)|*.std|OCAFSample(XML) (*.xml)|*.xml|OCAFSample(Binary) (*.cbf)|*.cbf||",
+//                     "std Files (*.std)|*.std; |All Files (*.*)|*.*||", 
                        NULL );
 
        if (dlg.DoModal() != IDOK) return;
@@ -1088,8 +1089,8 @@ m_App->SaveAs(myOcafDoc,(TCollection_ExtendedString) TPath); \n\
    }
 
 
-//     if((CSPath.Find(CString(".sta")))==-1 )
-//             CSPath = CSPath + ".sta";
+//     if((CSPath.Find(CString(".std")))==-1 )
+//             CSPath = CSPath + ".std";
 
 //     cout << "Save As " << CSPath << endl;
 //     PathName=CSPath;
diff --git a/samples/qt/VoxelDemo/VoxelDemo.sln b/samples/qt/VoxelDemo/VoxelDemo.sln
new file mode 100644 (file)
index 0000000..1e5a741
--- /dev/null
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VoxelDemo", "VoxelDemo.vcproj", "{EF9DFAE9-E10E-42D4-87D1-52431728AFDF}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Win32 = Debug|Win32
+               Release|Win32 = Release|Win32
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {EF9DFAE9-E10E-42D4-87D1-52431728AFDF}.Debug|Win32.ActiveCfg = Debug|Win32
+               {EF9DFAE9-E10E-42D4-87D1-52431728AFDF}.Debug|Win32.Build.0 = Debug|Win32
+               {EF9DFAE9-E10E-42D4-87D1-52431728AFDF}.Release|Win32.ActiveCfg = Release|Win32
+               {EF9DFAE9-E10E-42D4-87D1-52431728AFDF}.Release|Win32.Build.0 = Release|Win32
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/samples/qt/VoxelDemo/VoxelDemo.vcproj b/samples/qt/VoxelDemo/VoxelDemo.vcproj
new file mode 100644 (file)
index 0000000..538b89c
--- /dev/null
@@ -0,0 +1,291 @@
+<?xml version="1.0" encoding="windows-1251"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="8,00"
+       Name="VoxelDemo"
+       ProjectGUID="{EF9DFAE9-E10E-42D4-87D1-52431728AFDF}"
+       RootNamespace="VoxelDemo"
+       Keyword="Win32Proj"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               AdditionalIncludeDirectories="$(CSF_OPT_INC);.\inc"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WNT"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               Detect64BitPortabilityProblems="true"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               AdditionalDependencies="opengl32.lib glu32.lib TKernel.lib TKMath.lib TKGeomBase.lib TKV3d.lib TKService.lib TKG3d.lib TKVoxel.lib TKTopAlgo.lib TKBRep.lib TKPrim.lib TKOpenGl.lib vfw32.lib QtCore4.lib QtGui4.lib "
+                               LinkIncremental="2"
+                               AdditionalLibraryDirectories="$(CSF_OPT_LIB32D)"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               AdditionalIncludeDirectories="$(CSF_OPT_INC);.\inc"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WNT"
+                               RuntimeLibrary="2"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               Detect64BitPortabilityProblems="true"
+                               DebugInformationFormat="3"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               AdditionalDependencies="opengl32.lib glu32.lib TKernel.lib TKMath.lib TKGeomBase.lib TKV3d.lib TKService.lib TKG3d.lib TKVoxel.lib TKTopAlgo.lib TKBRep.lib TKPrim.lib TKOpenGl.lib vfw32.lib QtCore4.lib QtGui4.lib "
+                               LinkIncremental="1"
+                               AdditionalLibraryDirectories="$(CSF_OPT_LIB32)"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath=".\src\Application.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\ConversionThread.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\Main.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\Timer.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\Viewer.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\VoxelClient_VisDrawer.cxx"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Header Files"
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+                       >
+                       <File
+                               RelativePath=".\inc\Application.h"
+                               >
+                               <FileConfiguration
+                                       Name="Debug|Win32"
+                                       >
+                                       <Tool
+                                               Name="VCCustomBuildTool"
+                                               CommandLine="moc.exe inc\$(InputFileName) -o moc\moc_$(InputName).cpp"
+                                               Outputs="moc\moc_$(InputName).cpp"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release|Win32"
+                                       >
+                                       <Tool
+                                               Name="VCCustomBuildTool"
+                                               CommandLine="moc.exe inc\$(InputFileName) -o moc\moc_$(InputName).cpp"
+                                               Outputs="moc\moc_$(InputName).cpp"
+                                       />
+                               </FileConfiguration>
+                       </File>
+                       <File
+                               RelativePath=".\inc\ConversionThread.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\inc\Timer.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\inc\Viewer.h"
+                               >
+                               <FileConfiguration
+                                       Name="Debug|Win32"
+                                       >
+                                       <Tool
+                                               Name="VCCustomBuildTool"
+                                               CommandLine="moc.exe inc\$(InputFileName) -o moc\moc_$(InputName).cpp&#x0D;&#x0A;"
+                                               Outputs="moc\moc_$(InputName).cpp"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release|Win32"
+                                       >
+                                       <Tool
+                                               Name="VCCustomBuildTool"
+                                               CommandLine="moc.exe inc\$(InputFileName) -o moc\moc_$(InputName).cpp&#x0D;&#x0A;"
+                                               Outputs="moc\moc_$(InputName).cpp"
+                                       />
+                               </FileConfiguration>
+                       </File>
+                       <File
+                               RelativePath=".\inc\VoxelClient_VisDrawer.h"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Resource Files"
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+                       >
+               </Filter>
+               <Filter
+                       Name="moc"
+                       >
+                       <File
+                               RelativePath=".\moc\moc_Application.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\moc\moc_Viewer.cpp"
+                               >
+                       </File>
+               </Filter>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>
diff --git a/samples/qt/VoxelDemo/inc/Application.h b/samples/qt/VoxelDemo/inc/Application.h
new file mode 100644 (file)
index 0000000..59e63ea
--- /dev/null
@@ -0,0 +1,114 @@
+#ifndef APPLICATION_H
+#define APPLICATION_H
+
+#include <qmainwindow.h>
+#include <AIS_Shape.hxx>
+#include <Voxel_Prs.hxx>
+#include <Voxel_BoolDS.hxx>
+#include <Voxel_ColorDS.hxx>
+#include "Viewer.h"
+
+class Application: public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    Application();
+    ~Application();
+
+protected:
+    void closeEvent( QCloseEvent* );
+
+private slots:
+    void box();
+    void cylinder();
+    void torus();
+    void sphere();
+    void choose();
+    void load( const QString & );
+    void load( const TopoDS_Shape & );
+    void save();
+    void open();
+
+    void testBoolDS();
+    void testColorDS();
+    void testFloatDS();
+    void testOctBoolDS();
+    void testROctBoolDS();
+
+    void testFuseBoolDS();
+    void testFuseColorDS();
+    void testFuseFloatDS();
+    void testCutBoolDS();
+    void testCutColorDS();
+    void testCutFloatDS();
+    
+    void convert2bool();
+    void convert2color();
+    void convert(const int );
+
+    void setNbX();
+    void setNbY();
+    void setNbZ();
+
+    void setScanSide();
+
+    void setVolumicBoolValue();
+    void setVolumicColorValue();
+
+    void setQuadrangleSize();
+    void setPointSize();
+
+    void setColorMinValue();
+    void setColorMaxValue();
+
+    void setUsageOfGLlists();
+    
+    void setDisplayedXMin();
+    void setDisplayedXMax();
+    void setDisplayedYMin();
+    void setDisplayedYMax();
+    void setDisplayedZMin();
+    void setDisplayedZMax();
+
+    void displayPoints();
+    void displayNearestPoints();
+    void displayBoxes();
+    void displayNearestBoxes();
+
+    void displayColorScale();
+    
+    void displayWaves();
+    void displayCut();
+    void displayCollisions();
+
+    void about();
+
+private:
+    void display(Voxel_VoxelDisplayMode );
+    void initPrs();
+
+       Viewer* myViewer;
+       Handle(AIS_Shape) myShape;
+       Handle(Voxel_Prs) myVoxels;
+       Voxel_BoolDS* myBoolVoxels;
+       Voxel_ColorDS* myColorVoxels;
+       int myNbX;
+       int myNbY;
+       int myNbZ;
+    unsigned char myScanSide;
+    bool myVolumicBoolValue;
+    unsigned char myVolumicColorValue;
+    int myQuadrangleSize;
+    int myPointSize;
+    unsigned char myColorMinValue;
+    unsigned char myColorMaxValue;
+    double myDisplayedXMin;
+    double myDisplayedXMax;
+    double myDisplayedYMin;
+    double myDisplayedYMax;
+    double myDisplayedZMin;
+    double myDisplayedZMax;
+};
+
+#endif // APPLICATION_H
diff --git a/samples/qt/VoxelDemo/inc/ConversionThread.h b/samples/qt/VoxelDemo/inc/ConversionThread.h
new file mode 100644 (file)
index 0000000..7e66a94
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef _CONVERSIONTHREAD_H_
+#define _CONVERSIONTHREAD_H_
+
+#include <QThread.h>
+//#include <Voxel_Converter.hxx>
+#include <Voxel_FastConverter.hxx>
+
+class ConversionThread : public QThread
+{
+
+public:
+
+    ConversionThread();
+    ~ConversionThread();
+
+//    void setConverter(Voxel_Converter*     converter);
+    void setConverter(Voxel_FastConverter* converter);
+
+    void setVolumicValue(const int value);
+    void setScanSide(const int side);
+    void setThreadIndex(const int ithread);
+
+    int* getProgress();
+
+protected:
+
+    void run();
+
+private:
+
+//    Voxel_Converter*     myConverter;
+    Voxel_FastConverter* myFastConverter;
+
+    int myVolumicValue;
+    int myScanSide;
+    int myThreadIndex;
+    int myProgress;
+};
+
+#endif // _CONVERSIONTHREAD_H_
\ No newline at end of file
diff --git a/samples/qt/VoxelDemo/inc/Timer.h b/samples/qt/VoxelDemo/inc/Timer.h
new file mode 100644 (file)
index 0000000..338d7dc
--- /dev/null
@@ -0,0 +1,33 @@
+// Timer.h: interface for the Timer class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_TIMER_H__528FB454_797E_11D7_9B1B_000103C0F1F9__INCLUDED_)
+#define AFX_TIMER_H__528FB454_797E_11D7_9B1B_000103C0F1F9__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+#include <OSD_Timer.hxx>
+
+class Timer  
+{
+public:
+       Standard_EXPORT Timer();
+       Standard_EXPORT Timer(const char* filename);
+       Standard_EXPORT ~Timer();
+       Standard_EXPORT void Start();
+       Standard_EXPORT void Stop();
+       Standard_EXPORT void Continue();
+       Standard_EXPORT void Reset();
+  Standard_EXPORT float Seconds();
+  Standard_EXPORT int Minutes();
+       Standard_EXPORT void Print(char* label);
+
+private:
+       OSD_Timer myTimer;
+       FILE* myWriter;
+};
+
+#endif // !defined(AFX_TIMER_H__528FB454_797E_11D7_9B1B_000103C0F1F9__INCLUDED_)
diff --git a/samples/qt/VoxelDemo/inc/Viewer.h b/samples/qt/VoxelDemo/inc/Viewer.h
new file mode 100644 (file)
index 0000000..ee57227
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef _VIEWER_H_
+#define _VIEWER_H_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+#include <QWidget.h>
+
+#include <AIS_InteractiveContext.hxx>
+#include <V3d_View.hxx>
+
+#include <Voxel_Prs.hxx>
+#include <Voxel_Selector.hxx>
+
+class Viewer : public QWidget 
+{
+       
+       Q_OBJECT
+
+public:
+
+       Viewer(QWidget* parent);
+       virtual ~Viewer();
+
+       Handle(AIS_InteractiveContext) getIC() const { return myIC; }
+       Handle(V3d_View) getView() const { return myView; }
+    Voxel_Selector& getSelector() { return mySelector; }
+    void setPrs(const Handle(Voxel_Prs)& prs) { myPrs = prs; }
+       virtual QPaintEngine*          paintEngine() const;
+
+signals:
+       
+       void mousePressed(Qt::KeyboardModifiers,int,int);
+       void mouseMoved(Qt::KeyboardModifiers,int,int);
+       void mouseReleased(Qt::KeyboardModifiers,int,int);
+       void mouseDoubleClick(Qt::KeyboardModifiers,int,int);
+
+protected:
+       virtual void paintEvent(QPaintEvent* pEvent);
+       virtual void resizeEvent(QResizeEvent* rsEvent);
+       virtual void mousePressEvent(QMouseEvent* mpEvent);
+       virtual void mouseMoveEvent(QMouseEvent* mmEvent);
+       virtual void mouseReleaseEvent(QMouseEvent* mrEvent);
+       virtual void mouseDoubleClickEvent(QMouseEvent* mdcEvent);
+
+private:
+       Handle(AIS_InteractiveContext) myIC;
+       Handle(V3d_View)               myView;
+
+       bool myRotate;
+       bool myZoom;
+       bool myPan;
+
+       QPoint myStartPnt;
+
+    void setDegenerateMode(const bool );
+
+    Voxel_Selector mySelector;
+    Handle(Voxel_Prs) myPrs;
+};
+
+#endif // _VIEWER_H_
diff --git a/samples/qt/VoxelDemo/inc/VoxelClient_VisDrawer.h b/samples/qt/VoxelDemo/inc/VoxelClient_VisDrawer.h
new file mode 100644 (file)
index 0000000..cb89ac2
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ Copyright (c) 1999-2012 OPEN CASCADE SAS
+
+ The content of this file is subject to the Open CASCADE Technology Public
+ License Version 6.5 (the "License"). You may not use the content of this file
+ except in compliance with the License. Please obtain a copy of the License
+ at http://www.opencascade.org and read it completely before using this file.
+
+ The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+ main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+
+ The Original Code and all software distributed under the License is
+ distributed on an "AS IS" basis, without warranty of any kind, and the
+ Initial Developer hereby disclaims all such warranties, including without
+ limitation, any warranties of merchantability, fitness for a particular
+ purpose or non-infringement. Please see the License for the specific terms
+ and conditions governing the rights and limitations under the License.
+
+*/
+
+#ifndef _VOXEL_VISDRAWER_H_
+#define _VOXEL_VISDRAWER_H_
+
+#include "Voxel_VisData.h"
+#include <Graphic3d_CBounds.hxx>
+
+class VoxelClient_VisDrawer
+{
+public:
+
+  class VisElement;
+
+public:
+
+    Standard_EXPORT static void Init();
+
+       Standard_EXPORT VoxelClient_VisDrawer(Voxel_VisData* theData);
+       Standard_EXPORT virtual ~VoxelClient_VisDrawer();
+
+       Standard_EXPORT void EvalMinMax(Graphic3d_CBounds& theMinMax) const;
+       Standard_EXPORT void Display(const Standard_Boolean theHighlight);
+
+private:
+    
+       Standard_EXPORT void DisplayVoxels(const Standard_Boolean theHighlight);
+       Standard_EXPORT void DisplayPoints(const Standard_Boolean nearest);
+       Standard_EXPORT void DisplayBoxes(const Standard_Boolean nearest);
+    Standard_EXPORT void HighlightVoxel();
+       
+    Standard_EXPORT void DisplayTriangulation(const Standard_Boolean theHighlight);
+
+       Voxel_VisData* myData;
+};
+
+#endif // _VOXEL_VISDRAWER_H_
diff --git a/samples/qt/VoxelDemo/msvc.bat b/samples/qt/VoxelDemo/msvc.bat
new file mode 100644 (file)
index 0000000..fc42168
--- /dev/null
@@ -0,0 +1,6 @@
+set CASROOT=D:\OCC653\ros
+set QTDIR=D:\qt\4.8.2
+set PATH=%QTDIR%\bin;%PATH%
+
+call %CASROOT%/env.bat %1 %2 %3
+call %CASROOT%/msvc.bat %1 %2 %3 VoxelDemo.sln
diff --git a/samples/qt/VoxelDemo/src/Application.cpp b/samples/qt/VoxelDemo/src/Application.cpp
new file mode 100644 (file)
index 0000000..c4379b0
--- /dev/null
@@ -0,0 +1,2366 @@
+#include "Application.h"
+#include "ConversionThread.h"
+#include "Timer.h"
+
+#include <QPixmap.h>
+#include <QToolButton.h>
+#include <QWhatsThis.h>
+#include <QMenu.h>
+#include <QMenuBar.h>
+#include <QStatusBar.h>
+#include <QApplication.h>
+#include <QFileDialog.h>
+#include <QMessageBox.h>
+#include <QInputDialog.h>
+#include <QCloseEvent>
+
+#include <Voxel_BoolDS.hxx>
+#include <Voxel_ColorDS.hxx>
+#include <Voxel_FloatDS.hxx>
+#include <Voxel_OctBoolDS.hxx>
+#include <Voxel_ROctBoolDS.hxx>
+#include <Voxel_BooleanOperation.hxx>
+#include <Voxel_CollisionDetection.hxx>
+#include <Voxel_FastConverter.hxx>
+#include <Voxel_Writer.hxx>
+#include <Voxel_Reader.hxx>
+#include <VoxelClient_VisDrawer.h>
+
+#include <BRepTools.hxx>
+#include <BRepBndLib.hxx>
+#include <BRep_Builder.hxx>
+#include <BRepPrimAPI_MakeBox.hxx>
+#include <BRepPrimAPI_MakeTorus.hxx>
+#include <BRepPrimAPI_MakeSphere.hxx>
+#include <BRepPrimAPI_MakeCylinder.hxx>
+#include <Aspect_ColorScale.hxx>
+
+#include <Windows.h>
+
+Application::Application()
+    : QMainWindow( 0 )
+{
+    // File
+    QMenu * file = menuBar()->addMenu( "&File" );
+
+    QAction* a;
+    // Box
+    a = new QAction("Box", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(box()));
+    file->addAction(a);
+    // Cylinder
+    a = new QAction("Cylinder", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(cylinder()));
+    file->addAction(a);
+    // Torus
+    a = new QAction("Torus", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(torus()));
+    file->addAction(a);
+    // Sphere
+    a = new QAction("Sphere", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(sphere()));
+    file->addAction(a);
+    // Load shape...
+    a = new QAction("Load shape...", this);
+    a->setShortcut(tr("Ctrl+O"));
+    connect(a, SIGNAL(triggered()), this, SLOT(choose()));
+    file->addAction(a);
+
+    file->addSeparator();
+
+    // Open
+    a = new QAction("Open", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(open()));
+    file->addAction(a);
+
+    // Save
+    a = new QAction("Save", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(save()));
+    file->addAction(a);
+
+    file->addSeparator();
+
+    // Quit
+    a = new QAction("&Quit", this);
+    a->setShortcut(tr("Ctrl+Q"));
+    connect(a, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
+    file->addAction(a);
+
+    menuBar()->addSeparator();
+
+
+#ifdef TEST
+    QMenu * test = menuBar()->addMenu( "Test" );
+
+    a = new QAction("Test boolean", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(testBoolDS()));
+    test->addAction(a);
+
+    a = new QAction("Test color", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(testColorDS()));
+    test->addAction(a);
+
+    a = new QAction("Test float", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(testFloatDS()));
+    test->addAction(a);
+
+    a = new QAction("Test boolean / 8", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(testOctBoolDS()));
+    test->addAction(a);
+
+    a = new QAction("Test boolean / 8 / 8..", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(testROctBoolDS()));
+    test->addAction(a);
+
+    test->addSeparator();
+
+    a = new QAction("Test fusion of booleans", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(testFuseBoolDS()));
+    test->addAction(a);
+
+    a = new QAction("Test fusion of colors", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(testFuseColorDS()));
+    test->addAction(a);
+
+    a = new QAction("Test fusion of floating-points", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(testFuseFloatDS()));
+    test->addAction(a);
+
+    a = new QAction("Test cutting of booleans", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(testCutBoolDS()));
+    test->addAction(a);
+
+    a = new QAction("Test cutting of booleans", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(testCutColorDS()));
+    test->addAction(a);
+
+    a = new QAction("Test cutting of floating-points", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(testCutFloatDS()));
+    test->addAction(a);
+
+#endif // TEST
+
+    QMenu * converter = menuBar()->addMenu( "Converter" );
+
+#ifdef TEST
+    
+    a = new QAction("Number of splits along X", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setNbX()));
+    converter->addAction(a);
+
+    a = new QAction("Number of splits along Y", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setNbY()));
+    converter->addAction(a);
+
+    a = new QAction("Number of splits along Z", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setNbZ()));
+    converter->addAction(a);
+
+    converter->addSeparator();
+
+    a = new QAction("Side of scanning", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setScanSide()));
+    converter->addAction(a);
+
+    converter->addSeparator();
+
+    a = new QAction("Volumic value of 1bit voxels", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setVolumicBoolValue()));
+    converter->addAction(a);
+    
+    a = new QAction("Volumic value of 4bit voxels", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setVolumicColorValue()));
+    converter->addAction(a);
+
+    converter->addSeparator();
+
+#endif // TEST
+
+    a = new QAction("Convert to 1bit voxels", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(convert2bool()));
+    converter->addAction(a);
+
+    a = new QAction("Convert to 4bit voxels", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(convert2color()));
+    converter->addAction(a);
+
+    QMenu * vis = menuBar()->addMenu( "&Visualization" );
+
+    a = new QAction("Points", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(displayPoints()));
+    vis->addAction(a);
+
+#ifdef TEST
+    
+    a = new QAction("Nearest points", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(displayNearestPoints()));
+    vis->addAction(a);
+
+#endif // TEST
+
+    a = new QAction("Boxes", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(displayBoxes()));
+    vis->addAction(a);
+
+#ifdef TEST
+
+    a = new QAction("Nearest boxes", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(displayNearestBoxes()));
+    vis->addAction(a);
+
+#endif // TEST
+    
+    vis->addSeparator();
+
+    a = new QAction("Point size", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setPointSize()));
+    vis->addAction(a);
+    
+    a = new QAction("Quadrangle size (%)", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setQuadrangleSize()));
+    vis->addAction(a);
+
+    vis->addSeparator();
+
+    a = new QAction("Color min value", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setColorMinValue()));
+    vis->addAction(a);
+
+    a = new QAction("Color max value", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setColorMaxValue()));
+    vis->addAction(a);
+
+#ifdef TEST
+
+    vis->addSeparator();
+
+    a = new QAction("Use GL lists", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setUsageOfGLlists()));
+    vis->addAction(a);
+
+#endif // TEST
+
+    vis->addSeparator();
+
+    a = new QAction("Displayed X min", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setDisplayedXMin()));
+    vis->addAction(a);
+
+    a = new QAction("Displayed X max", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setDisplayedXMax()));
+    vis->addAction(a);
+
+    a = new QAction("Displayed Y min", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setDisplayedYMin()));
+    vis->addAction(a);
+
+    a = new QAction("Displayed Y max", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setDisplayedYMax()));
+    vis->addAction(a);
+
+    a = new QAction("Displayed Z min", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setDisplayedZMin()));
+    vis->addAction(a);
+
+    a = new QAction("Displayed Z max", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(setDisplayedZMax()));
+    vis->addAction(a);
+
+
+    QMenu * demo = menuBar()->addMenu( "Demo" );
+
+    a = new QAction("Waves", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(displayWaves()));
+    demo->addAction(a);
+
+    a = new QAction("Cut", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(displayCut()));
+    demo->addAction(a);
+
+    a = new QAction("Collisions", this);
+    connect(a, SIGNAL(triggered()), this, SLOT(displayCollisions()));
+    demo->addAction(a);
+
+
+    QMenu * help = menuBar()->addMenu( "Help" );
+
+    a = new QAction("About", this);
+    a->setShortcut(tr("F1"));
+    connect(a, SIGNAL(triggered()), this, SLOT(about()));
+    help->addAction(a);
+
+
+    myViewer = new Viewer( this );
+    myViewer->setFocus();
+    setCentralWidget( myViewer );
+    statusBar()->showMessage( "Ready", 2000 );
+
+       myNbX = 100;
+       myNbY = 100;
+       myNbZ = 100;
+
+    myScanSide = 7;
+
+    myVolumicBoolValue = false;
+    myVolumicColorValue = 0;
+
+    myQuadrangleSize = 40;
+    
+    myColorMinValue = 1;
+    myColorMaxValue = 15;
+
+       myBoolVoxels = 0;
+       myColorVoxels = 0;
+
+    myDisplayedXMin = -DBL_MAX;
+    myDisplayedXMax =  DBL_MAX;
+    myDisplayedYMin = -DBL_MAX;
+    myDisplayedYMax =  DBL_MAX;
+    myDisplayedZMin = -DBL_MAX;
+    myDisplayedZMax =  DBL_MAX;
+
+       VoxelClient_VisDrawer::Init();
+
+    resize( 450, 600 );
+}
+
+Application::~Application()
+{
+       if (myBoolVoxels)
+               delete myBoolVoxels;
+       if (myColorVoxels)
+               delete myColorVoxels;
+}
+
+void Application::choose()
+{
+    QString fn = QFileDialog::getOpenFileName( this, QString::null, QString::null, "*.brep");
+    if ( !fn.isEmpty() )
+               load( fn );
+    else
+               statusBar()->showMessage( "Loading aborted", 2000 );
+}
+
+void Application::load( const QString &fileName )
+{
+    QFile f( fileName );
+    if ( !f.open( QIODevice::ReadOnly ) )
+               return;
+
+    // Read shape
+       TopoDS_Shape S;
+       BRep_Builder B;
+       if (!BRepTools::Read(S, (char*) fileName.constData(), B))
+               statusBar()->showMessage( "Loading failed", 2000 );
+    
+    load(S);
+}
+
+void Application::open()
+{
+    QString fn = QFileDialog::getOpenFileName( this, QString::null, QString::null, "*.vx");
+    if ( fn.isEmpty() || !QFile::exists(fn) )
+    {
+               statusBar()->showMessage( "Open aborted", 2000 );
+        return;
+    }
+
+    Timer timer;
+    timer.Start();
+
+    // Read the voxels
+    Voxel_Reader reader;
+    if (!reader.Read((char*)fn.constData()))
+    {
+               statusBar()->showMessage( "Open failed... sorry", 2000 );
+        return;
+    }
+
+    timer.Stop();
+    timer.Print("Open");
+
+    // Release current voxels
+    if (myBoolVoxels)
+    {
+        delete myBoolVoxels;
+        myBoolVoxels = 0;
+    }
+    if (myColorVoxels)
+    {
+        delete myColorVoxels;
+        myColorVoxels = 0;
+    }
+
+    // Take the voxels
+    if (reader.IsBoolVoxels())
+    {
+        myBoolVoxels = (Voxel_BoolDS*) reader.GetBoolVoxels();
+        myViewer->getSelector().SetVoxels(*myBoolVoxels);
+    }
+    else if (reader.IsColorVoxels())
+    {
+        myColorVoxels = (Voxel_ColorDS*) reader.GetColorVoxels();
+        myViewer->getSelector().SetVoxels(*myColorVoxels);
+    }
+    
+    // Display the voxels
+    myViewer->getIC()->EraseAll(false, false);
+    Voxel_DS* ds = myBoolVoxels;
+    if (!ds)
+        ds = myColorVoxels;
+    if (ds)
+    {
+        myDisplayedXMin = ds->GetX() - 10.0 * Precision::Confusion();
+        myDisplayedXMax = ds->GetX() + ds->GetXLen() + 10.0 * Precision::Confusion();
+        myDisplayedYMin = ds->GetY() - 10.0 * Precision::Confusion();
+        myDisplayedYMax = ds->GetY() + ds->GetYLen() + 10.0 * Precision::Confusion();
+        myDisplayedZMin = ds->GetZ() - 10.0 * Precision::Confusion();
+        myDisplayedZMax = ds->GetZ() + ds->GetZLen() + 10.0 * Precision::Confusion();
+    }
+
+    // Init visual data
+    initPrs();
+
+    // Set voxels and display
+    Handle(Poly_Triangulation) empty;
+    myVoxels->SetBoolVoxels(myBoolVoxels);
+       myVoxels->SetColorVoxels(myColorVoxels);
+    myVoxels->SetTriangulation(empty);
+    if (myViewer->getIC()->IsDisplayed(myVoxels))
+        myViewer->getIC()->Redisplay(myVoxels, false);
+    else
+           myViewer->getIC()->Display(myVoxels, false);
+   
+    // Color scale
+    if (myColorVoxels)
+        displayColorScale();
+    else
+        myViewer->getView()->ColorScaleErase();
+
+       myViewer->getView()->FitAll();
+
+    statusBar()->showMessage( "Ready.", 2000 );
+}
+
+void Application::save()
+{
+    QString fn = QFileDialog::getSaveFileName( this, QString::null, QString::null, "*.vx");
+    if ( fn.isEmpty() )
+    {
+               statusBar()->showMessage( "Storage aborted", 2000 );
+        return;
+    }
+    if (fn.indexOf(".vx", -1, Qt::CaseInsensitive) == -1)
+        fn += ".vx";
+
+    Timer timer;
+    timer.Start();
+
+    // Write the voxels
+    Voxel_Writer writer;
+    writer.SetFormat(Voxel_VFF_BINARY);
+    if (myBoolVoxels)
+        writer.SetVoxels(*myBoolVoxels);
+    else if (myColorVoxels)
+        writer.SetVoxels(*myColorVoxels);
+    else
+    {
+               statusBar()->showMessage( "Nothing to store", 2000 );
+        return;
+    }
+    if (!writer.Write((char*)fn.constData()))
+    {
+               statusBar()->showMessage( "Storage failed... sorry", 2000 );
+        return;
+    }
+
+    timer.Stop();
+    timer.Print("Save");
+
+    statusBar()->showMessage( "Saved.", 2000 );
+}
+
+void Application::closeEvent( QCloseEvent* ce )
+{
+    ce->accept();
+}
+
+void Application::about()
+{
+    QMessageBox::about( this, "Voxel demo-application",
+                       "This example demonstrates simple usage of "
+                       "voxel models of Open CASCADE.");
+}
+
+void Application::testBoolDS()
+{
+       Timer timer;
+       int ix, iy, iz;
+       int nbx = 100, nby = 100, nbz = 100;
+
+
+       // 1. BoolDS:
+
+       timer.Start();
+
+       Voxel_BoolDS ds(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               if (ix & 0x01)
+                                       ds.Set(ix, iy, iz, false);
+                               else
+                                       ds.Set(ix, iy, iz, true);
+                       }
+               }
+       }
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               bool value = ds.Get(ix, iy, iz) == Standard_True;
+                               if (ix & 0x01)
+                               {
+                                       if (value != false)
+                                               cout<<"Wrong value!"<<endl;
+                               }
+                               else
+                               {
+                                       if (value != true)
+                                               cout<<"Wrong value!"<<endl;
+                               }
+                       }
+               }
+       }
+
+       timer.Stop();
+       timer.Print("BoolDS");
+}
+
+void Application::testColorDS()
+{
+       Timer timer;
+       int ix, iy, iz;
+       int nbx = 100, nby = 100, nbz = 100;
+
+
+       // 1. ColorDS:
+
+       timer.Start();
+
+       Voxel_ColorDS ds(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                if (ix & 0x01)
+                           ds.Set(ix, iy, iz, 8);
+                else
+                    ds.Set(ix, iy, iz, 7);
+                       }
+               }
+       }
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               unsigned char value = ds.Get(ix, iy, iz);
+                if (ix & 0x01)
+                {
+                                   if (value != 8)
+                                           cout<<"Wrong value!"<<endl;
+                }
+                else
+                {
+                                   if (value != 7)
+                                           cout<<"Wrong value!"<<endl;
+                }
+                       }
+               }
+       }
+
+       timer.Stop();
+       timer.Print("ColorDS");
+}
+
+void Application::testFloatDS()
+{
+       Timer timer;
+       int ix, iy, iz;
+       int nbx = 100, nby = 100, nbz = 100;
+
+
+       // 1. FloatDS:
+
+       timer.Start();
+
+       Voxel_FloatDS ds(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                if (ix & 0x01)
+                           ds.Set(ix, iy, iz, 8.8f);
+                else
+                    ds.Set(ix, iy, iz, 7.7f);
+                       }
+               }
+       }
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               float value = ds.Get(ix, iy, iz);
+                if (ix & 0x01)
+                {
+                                   if (value != 8.8f)
+                                           cout<<"Wrong value!"<<endl;
+                }
+                else
+                {
+                                   if (value != 7.7f)
+                                           cout<<"Wrong value!"<<endl;
+                }
+                       }
+               }
+       }
+
+       timer.Stop();
+       timer.Print("FloatDS");
+}
+
+void Application::testOctBoolDS()
+{
+       Timer timer;
+       int ix, iy, iz;
+       int nbx = 30, nby = 30, nbz = 30;
+
+
+       // 1. OctBoolDS:
+
+       timer.Start();
+
+       Voxel_OctBoolDS ds(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               if (ix & 0x01)
+                {
+                                       ds.Set(ix, iy, iz, true);
+                }
+                               else
+                {
+                    for (int i = 0; i < 8; i++)
+                    {
+                        if (i & 0x01)
+                                               ds.Set(ix, iy, iz, i, true);
+                        else
+                            ds.Set(ix, iy, iz, i, false);
+                    }
+                }
+                       }
+               }
+       }
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               if (ix & 0x01)
+                               {
+                               bool value = ds.Get(ix, iy, iz) == Standard_True;
+                                       if (value != true)
+                                               cout<<"Wrong value!"<<endl;
+                               }
+                               else
+                               {
+                    for (int i = 0; i < 8; i++)
+                    {
+                        if (i & 0x01)
+                        {
+                                       bool value = ds.Get(ix, iy, iz, i) == Standard_True;
+                                               if (value != true)
+                                                       cout<<"Wrong value!"<<endl;
+                        }
+                        else
+                        {
+                                       bool value = ds.Get(ix, iy, iz, i) == Standard_True;
+                                               if (value != false)
+                                                       cout<<"Wrong value!"<<endl;
+                        }
+                    }
+                               }
+                       }
+               }
+       }
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               if (ix & 0x01)
+                               {
+                    for (int i = 0; i < 8; i++)
+                    {
+                        ds.Set(ix, iy, iz, i, true);
+                    }
+                               }
+                else
+                {
+                    for (int i = 0; i < 8; i++)
+                    {
+                        ds.Set(ix, iy, iz, i, false);
+                    }
+                }
+                       }
+               }
+       }
+
+    ds.OptimizeMemory();
+
+       timer.Stop();
+       timer.Print("OctBoolDS");
+}
+
+void Application::testROctBoolDS()
+{
+       Timer timer;
+       int ix, iy, iz, i, j;
+       int nbx = 30, nby = 30, nbz = 30;
+
+       // 1. ROctBoolDS:
+
+       timer.Start();
+
+       Voxel_ROctBoolDS ds(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+
+    for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                ds.Set(ix, iy, iz, true);
+                       }
+               }
+       }
+
+    for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                for (i = 0; i < 8; i++)
+                {
+                    for (j = 0; j < 8; j++)
+                    {
+                        ds.Set(ix, iy, iz, i, j, true);
+                    }
+                }
+                       }
+               }
+       }
+
+    ds.OptimizeMemory();
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                if (ds.Deepness(ix, iy, iz) == 0)
+                {
+                    bool value = ds.Get(ix, iy, iz);
+                    if (value != true)
+                        cout<<"Wrong value..."<<endl;
+                }
+                if (ds.Deepness(ix, iy, iz) == 1)
+                {
+                    for (i = 0; i < 8; i++)
+                    {
+                        bool value = ds.Get(ix, iy, iz, i);
+                        if (value != true)
+                            cout<<"Wrong value..."<<endl;
+                    }
+                }
+                if (ds.Deepness(ix, iy, iz) == 2)
+                {
+                    for (i = 0; i < 8; i++)
+                    {
+                        for (j = 0; j < 8; j++)
+                        {
+                            bool value = ds.Get(ix, iy, iz, i, j);
+                            if (value != true)
+                                cout<<"Wrong value..."<<endl;
+                        }
+                    }
+                }
+                       }
+               }
+       }
+
+       timer.Stop();
+       timer.Print("ROctBoolDS");
+
+
+    // Test converter
+    TopoDS_Shape S = BRepPrimAPI_MakeSphere(100.0);
+
+    timer.Start();
+
+    int progress = 0;
+    Voxel_ROctBoolDS* ds2 = new Voxel_ROctBoolDS;
+    Voxel_FastConverter converter(S, *ds2, 0.1, myNbX, myNbY, myNbZ, 1);
+    converter.Convert(progress);
+    ds2->OptimizeMemory();
+
+       timer.Stop();
+       timer.Print("ROctBoolDS::converter");
+
+
+    // Display 
+    myViewer->getIC()->EraseAll(false, false);
+    initPrs();
+    myVoxels->SetBoolVoxels(0);
+       myVoxels->SetColorVoxels(0);
+    Handle(Poly_Triangulation) empty;
+    myVoxels->SetTriangulation(empty);
+    myVoxels->SetROctBoolVoxels(ds2);
+    myViewer->getIC()->Display(myVoxels, false);
+    myViewer->getView()->ColorScaleErase();
+       myViewer->getView()->FitAll();
+    myViewer->getSelector().SetVoxels(*ds2);
+}
+
+void Application::testFuseBoolDS()
+{
+       Timer timer;
+       int ix, iy, iz;
+       int nbx = 100, nby = 100, nbz = 100;
+
+
+       // 1. Set two BoolDS:
+
+       timer.Start();
+
+       Voxel_BoolDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+       Voxel_BoolDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               if (ix & 0x01)
+                                       ds2.Set(ix, iy, iz, false);
+                               else
+                                       ds2.Set(ix, iy, iz, true);
+                       }
+               }
+       }
+
+    // 2. Fuse them
+
+    Voxel_BooleanOperation fuser;
+    if (!fuser.Fuse(ds1, ds2))
+        cout<<"The operation failed..."<<endl;
+
+    // 3. Check result
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               bool value = ds1.Get(ix, iy, iz) == Standard_True;
+                               if (ix & 0x01)
+                               {
+                                       if (value != false)
+                                       cout<<"Wrong value!"<<endl;
+                               }
+                               else
+                               {
+                                       if (value != true)
+                                               cout<<"Wrong value!"<<endl;
+                               }
+                       }
+               }
+       }
+
+       timer.Stop();
+       timer.Print("Fusion of BoolDS");
+}
+
+void Application::testFuseColorDS()
+{
+       Timer timer;
+       int ix, iy, iz;
+       int nbx = 100, nby = 100, nbz = 100;
+
+
+       // 1. Set two ColorDS:
+
+       timer.Start();
+
+       Voxel_ColorDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+       Voxel_ColorDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               ds1.Set(ix, iy, iz, 11);
+                       }
+               }
+       }
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               if (ix & 0x01)
+                                       ds2.Set(ix, iy, iz, 3);
+                               else
+                                       ds2.Set(ix, iy, iz, 5);
+                       }
+               }
+       }
+
+    // 2. Fuse them
+
+    Voxel_BooleanOperation fuser;
+    if (!fuser.Fuse(ds1, ds2))
+        cout<<"The operation failed..."<<endl;
+
+    // 3. Check result
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               unsigned char value = ds1.Get(ix, iy, iz);
+                               if (ix & 0x01)
+                               {
+                                       if (value != 14)
+                                       cout<<"Wrong value!"<<endl;
+                               }
+                               else
+                               {
+                                       if (value != 15)
+                                               cout<<"Wrong value!"<<endl;
+                               }
+                       }
+               }
+       }
+
+       timer.Stop();
+       timer.Print("Fusion of ColorDS");
+}
+
+void Application::testFuseFloatDS()
+{
+       Timer timer;
+       int ix, iy, iz;
+       int nbx = 100, nby = 100, nbz = 100;
+
+
+       // 1. Set two FloatDS:
+
+       timer.Start();
+
+       Voxel_FloatDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+       Voxel_FloatDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               ds1.Set(ix, iy, iz, 11.1f);
+                       }
+               }
+       }
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               if (ix & 0x01)
+                                       ds2.Set(ix, iy, iz, 3.3f);
+                               else
+                                       ds2.Set(ix, iy, iz, 5.5f);
+                       }
+               }
+       }
+
+    // 2. Fuse them
+
+    Voxel_BooleanOperation fuser;
+    if (!fuser.Fuse(ds1, ds2))
+        cout<<"The operation failed..."<<endl;
+
+    // 3. Check result
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               float value = ds1.Get(ix, iy, iz);
+                               if (ix & 0x01)
+                               {
+                    if (fabs(value - 14.4f) > 0.001)
+                                       cout<<"Wrong value!"<<endl;
+                               }
+                               else
+                               {
+                    if (fabs(value - 16.6f) > 0.001)
+                                               cout<<"Wrong value!"<<endl;
+                               }
+                       }
+               }
+       }
+
+       timer.Stop();
+       timer.Print("Fusion of FloatDS");
+}
+
+void Application::testCutBoolDS()
+{
+       Timer timer;
+       int ix, iy, iz;
+       int nbx = 100, nby = 100, nbz = 100;
+
+
+       // 1. Set two BoolDS:
+
+       timer.Start();
+
+       Voxel_BoolDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+       Voxel_BoolDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               ds1.Set(ix, iy, iz, true);
+                       }
+               }
+       }
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               if (ix & 0x01)
+                                       ds2.Set(ix, iy, iz, false);
+                               else
+                                       ds2.Set(ix, iy, iz, true);
+                       }
+               }
+       }
+
+    // 2. Cut them
+
+    Voxel_BooleanOperation cutter;
+    if (!cutter.Cut(ds1, ds2))
+        cout<<"The operation failed..."<<endl;
+
+    // 3. Check result
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               bool value = ds1.Get(ix, iy, iz) == Standard_True;
+                               if (ix & 0x01)
+                               {
+                                       if (value != true)
+                                       cout<<"Wrong value!"<<endl;
+                               }
+                               else
+                               {
+                                       if (value != false)
+                                               cout<<"Wrong value!"<<endl;
+                               }
+                       }
+               }
+       }
+
+       timer.Stop();
+       timer.Print("Cut of BoolDS");
+}
+
+void Application::testCutColorDS()
+{
+       Timer timer;
+       int ix, iy, iz;
+       int nbx = 100, nby = 100, nbz = 100;
+
+
+       // 1. Set two ColorDS:
+
+       timer.Start();
+
+       Voxel_ColorDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+       Voxel_ColorDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               ds1.Set(ix, iy, iz, 11);
+                       }
+               }
+       }
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               if (ix & 0x01)
+                                       ds2.Set(ix, iy, iz, 3);
+                               else
+                                       ds2.Set(ix, iy, iz, 5);
+                       }
+               }
+       }
+
+    // 2. Cut them
+
+    Voxel_BooleanOperation cutter;
+    if (!cutter.Cut(ds1, ds2))
+        cout<<"The operation failed..."<<endl;
+
+    // 3. Check result
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               unsigned char value = ds1.Get(ix, iy, iz);
+                               if (ix & 0x01)
+                               {
+                                       if (value != 8)
+                                       cout<<"Wrong value!"<<endl;
+                               }
+                               else
+                               {
+                                       if (value != 6)
+                                               cout<<"Wrong value!"<<endl;
+                               }
+                       }
+               }
+       }
+
+       timer.Stop();
+       timer.Print("Cut of ColorDS");
+}
+
+void Application::testCutFloatDS()
+{
+       Timer timer;
+       int ix, iy, iz;
+       int nbx = 100, nby = 100, nbz = 100;
+
+
+       // 1. Set two FloatDS:
+
+       timer.Start();
+
+       Voxel_FloatDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+       Voxel_FloatDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz);
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               ds1.Set(ix, iy, iz, 11.1f);
+                       }
+               }
+       }
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               if (ix & 0x01)
+                                       ds2.Set(ix, iy, iz, 3.3f);
+                               else
+                                       ds2.Set(ix, iy, iz, 5.5f);
+                       }
+               }
+       }
+
+    // 2. Cut them
+
+    Voxel_BooleanOperation cutter;
+    if (!cutter.Cut(ds1, ds2))
+        cout<<"The operation failed..."<<endl;
+
+    // 3. Check result
+
+       for (ix = 0; ix < nbx; ix++)
+       {
+               for (iy = 0; iy < nby; iy++)
+               {
+                       for (iz = 0; iz < nbz; iz++)
+                       {
+                               float value = ds1.Get(ix, iy, iz);
+                               if (ix & 0x01)
+                               {
+                    if (fabs(value - 7.8f) > 0.001)
+                                       cout<<"Wrong value!"<<endl;
+                               }
+                               else
+                               {
+                    if (fabs(value - 5.6f) > 0.001)
+                                               cout<<"Wrong value!"<<endl;
+                               }
+                       }
+               }
+       }
+
+       timer.Stop();
+       timer.Print("Cut of FloatDS");
+}
+
+void Application::convert2bool()
+{
+    convert(0);
+}
+
+void Application::convert2color()
+{
+    convert(1);
+}
+
+void Application::convert(const int ivoxel)
+{
+       TopoDS_Shape S;
+       if (!myShape.IsNull())
+               S = myShape->Shape();
+    if (S.IsNull())
+       {
+               QMessageBox::warning( this, "Voxel demo-application", "No shape for conversion!");
+               return;
+       }
+
+    switch (ivoxel)
+    {
+        case 0:
+        {
+               if (!myBoolVoxels)
+                       myBoolVoxels = new Voxel_BoolDS;
+            if (myColorVoxels)
+            {
+                delete myColorVoxels;
+                myColorVoxels = 0;
+            }
+            break;
+        }
+        case 1:
+        {
+               if (!myColorVoxels)
+                       myColorVoxels = new Voxel_ColorDS;
+            if (myBoolVoxels)
+            {
+                delete myBoolVoxels;
+                myBoolVoxels = 0;
+            }
+            break;
+        }
+    }
+
+    switch (ivoxel)
+    {
+        case 0:
+        {
+            Timer timer;
+            timer.Start();
+
+            /*
+            int progress;
+            Voxel_Converter converter(S, *myBoolVoxels, myNbX, myNbY, myNbZ);
+               if (!converter.Convert(progress, myVolumicBoolValue, myScanSide))
+               {
+                       QMessageBox::warning( this, "Voxel demo-application", "Conversion failed...");
+                       return;
+               }
+            */
+
+            /*
+            Voxel_Converter converter(S, *myBoolVoxels, myNbX, myNbY, myNbZ, 2);
+            ConversionThread thread1, thread2;
+            
+            thread1.setConverter(&converter);
+            thread2.setConverter(&converter);
+
+            thread1.setVolumicValue(myVolumicBoolValue);
+            thread2.setVolumicValue(myVolumicBoolValue);
+
+            thread1.setScanSide(myScanSide);
+            thread2.setScanSide(myScanSide);
+
+            thread1.setThreadIndex(1);
+            thread2.setThreadIndex(2);
+
+            thread1.start();
+            thread2.start();
+
+            while (thread1.running() || thread2.running())
+            {
+                ::Sleep(100);
+            }
+            */
+
+            /*
+            int progress;
+            Voxel_FastConverter converter(S, *myBoolVoxels, 0.1, myNbX, myNbY, myNbZ, 1);
+            converter.Convert(progress, 1);
+            //if (myVolumicBoolValue)
+            //    converter.FillInVolume(myVolumicBoolValue);
+            */
+
+            Voxel_FastConverter converter(S, *myBoolVoxels, 0.1, myNbX, myNbY, myNbZ, 2);
+            ConversionThread thread1, thread2;
+            
+            thread1.setConverter(&converter);
+            thread2.setConverter(&converter);
+
+            thread1.setThreadIndex(1);
+            thread2.setThreadIndex(2);
+
+            thread1.start();
+            thread2.start();
+
+            while (thread1.isRunning() || thread2.isRunning())
+            {
+                ::Sleep(100);
+            }
+
+            timer.Print("Converter");
+
+            myViewer->getSelector().SetVoxels(*myBoolVoxels);
+            break;
+        }
+        case 1:
+        {
+
+            Timer timer;
+            timer.Start();
+
+            /*
+            int progress;
+            Voxel_Converter converter(S, *myColorVoxels, myNbX, myNbY, myNbZ);
+               if (!converter.Convert(progress, myVolumicColorValue, myScanSide))
+               {
+                       QMessageBox::warning( this, "Voxel demo-application", "Conversion failed...");
+                       return;
+               }
+            */
+
+            /*
+            Voxel_Converter converter(S, *myColorVoxels, myNbX, myNbY, myNbZ, 2);
+            ConversionThread thread1, thread2;
+            
+            thread1.setConverter(&converter);
+            thread2.setConverter(&converter);
+
+            thread1.setVolumicValue(myVolumicColorValue);
+            thread2.setVolumicValue(myVolumicColorValue);
+
+            thread1.setScanSide(myScanSide);
+            thread2.setScanSide(myScanSide);
+
+            thread1.setThreadIndex(1);
+            thread2.setThreadIndex(2);
+
+            thread1.start();
+            thread2.start();
+
+            while (thread1.running() || thread2.running())
+            {
+                ::Sleep(100);
+            }
+            */
+
+            /*
+            int progress;
+            Voxel_FastConverter converter(S, *myColorVoxels, myNbX, myNbY, myNbZ, 1);
+            converter.Convert(progress, 1);
+            if (myVolumicColorValue)
+                converter.FillInVolume(myVolumicColorValue);
+            */
+
+            Voxel_FastConverter converter(S, *myColorVoxels, 0.1, myNbX, myNbY, myNbZ, 2);
+            ConversionThread thread1, thread2;
+            
+            thread1.setConverter(&converter);
+            thread2.setConverter(&converter);
+
+            thread1.setThreadIndex(1);
+            thread2.setThreadIndex(2);
+
+            thread1.start();
+            thread2.start();
+
+            while (thread1.isRunning() || thread2.isRunning())
+            {
+                ::Sleep(100);
+            }
+
+            timer.Print("Converter");
+
+
+            // Set color for demonstration
+            double maxd = 
+                fabs(myColorVoxels->GetX()) > fabs(myColorVoxels->GetY()) ? 
+                fabs(myColorVoxels->GetX()) : fabs(myColorVoxels->GetY());
+            maxd = maxd > fabs(myColorVoxels->GetZ()) ? maxd : fabs(myColorVoxels->GetZ());
+            maxd = maxd > fabs(myColorVoxels->GetX() + myColorVoxels->GetXLen()) ?
+                maxd : fabs(myColorVoxels->GetX() + myColorVoxels->GetXLen());
+            maxd = maxd > fabs(myColorVoxels->GetY() + myColorVoxels->GetYLen()) ?
+                maxd : fabs(myColorVoxels->GetY() + myColorVoxels->GetYLen());
+            maxd = maxd > fabs(myColorVoxels->GetZ() + myColorVoxels->GetZLen()) ?
+                maxd : fabs(myColorVoxels->GetZ() + myColorVoxels->GetZLen());
+            for (int ix = 0; ix < myNbX; ix++)
+            {
+                for (int iy = 0; iy < myNbY; iy++)
+                {
+                    for (int iz = 0; iz < myNbZ; iz++)
+                    {
+                        unsigned char value = myColorVoxels->Get(ix, iy, iz);
+                        if (value)
+                        {
+                            double xc, yc, zc, xd, yd, zd;
+                            myColorVoxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            xd = fabs(xc);
+                            yd = fabs(yc);
+                            zd = fabs(zc);
+                            double mind = xd < yd ? xd : yd;
+                            mind = zd < mind ? zd : mind;
+                            value = unsigned char(15.0 * (maxd - mind) / maxd);
+                            if (value <= 0)
+                                value = 1;
+                            myColorVoxels->Set(ix, iy, iz, value);
+                        }
+                    }
+                }
+            }
+
+            myViewer->getSelector().SetVoxels(*myColorVoxels);
+            break;
+        }
+    }
+
+    myViewer->getIC()->EraseAll(false, false);
+
+    Voxel_DS* ds = myBoolVoxels;
+    if (!ds)
+        ds = myColorVoxels;
+    if (ds)
+    {
+        myDisplayedXMin = ds->GetX() - 10.0 * Precision::Confusion();
+        myDisplayedXMax = ds->GetX() + ds->GetXLen() + 10.0 * Precision::Confusion();
+        myDisplayedYMin = ds->GetY() - 10.0 * Precision::Confusion();
+        myDisplayedYMax = ds->GetY() + ds->GetYLen() + 10.0 * Precision::Confusion();
+        myDisplayedZMin = ds->GetZ() - 10.0 * Precision::Confusion();
+        myDisplayedZMax = ds->GetZ() + ds->GetZLen() + 10.0 * Precision::Confusion();
+    }
+
+    // Init visual data
+    initPrs();
+
+    // Set voxels and display
+    Handle(Poly_Triangulation) empty;
+    myVoxels->SetBoolVoxels(myBoolVoxels);
+       myVoxels->SetColorVoxels(myColorVoxels);
+    myVoxels->SetTriangulation(empty);
+    if (myViewer->getIC()->IsDisplayed(myVoxels))
+        myViewer->getIC()->Redisplay(myVoxels, false);
+    else
+           myViewer->getIC()->Display(myVoxels, false);
+    
+    // Color scale
+    if (myColorVoxels)
+        displayColorScale();
+    else
+        myViewer->getView()->ColorScaleErase();
+
+       myViewer->getView()->FitAll();
+}
+
+void Application::setNbX()
+{
+       bool ok;
+       myNbX = 
+               QInputDialog::getInteger(this, "Voxel demo-application", "Number of splits in X-direction:", myNbX,
+                                                                                                                1, 100000, 1, &ok);
+}
+
+void Application::setNbY()
+{
+       bool ok;
+       myNbY = 
+               QInputDialog::getInteger(this, "Voxel demo-application", "Number of splits in X-direction:", myNbY,
+                                                                                                                1, 100000, 1, &ok);
+}
+
+void Application::setNbZ()
+{
+       bool ok;
+       myNbZ = 
+               QInputDialog::getInteger(this, "Voxel demo-application", "Number of splits in X-direction:", myNbZ,
+                                                                                                                1, 100000, 1, &ok);
+}
+
+void Application::setColorMinValue()
+{
+       bool ok;
+       myColorMinValue = 
+               QInputDialog::getInteger(this, "Voxel demo-application", "Minimum value for color [0 .. 15]:", myColorMinValue,
+                                                                0, 15, 1, &ok);
+    if (!myVoxels.IsNull())
+        myVoxels->SetColorRange(myColorMinValue, myColorMaxValue);
+}
+
+void Application::setColorMaxValue()
+{
+       bool ok;
+       myColorMaxValue = 
+               QInputDialog::getInteger(this, "Voxel demo-application", "Maximum value for color [0 .. 15]:", myColorMaxValue,
+                                                                0, 15, 1, &ok);
+    if (!myVoxels.IsNull())
+        myVoxels->SetColorRange(myColorMinValue, myColorMaxValue);
+}
+
+void Application::setUsageOfGLlists()
+{
+    int res = QMessageBox::question( this, "Voxel demo-application", "Press Yes to use GL lists and No not to use them.", QMessageBox::Yes, QMessageBox::No);
+    if (!myVoxels.IsNull())
+        myVoxels->SetUsageOfGLlists(res == QMessageBox::Yes);
+}
+
+void Application::setDisplayedXMin()
+{
+       myDisplayedXMin = QInputDialog::getDouble(this, "Voxel demo-application", "Minimum X value:", myDisplayedXMin);
+    if (!myVoxels.IsNull())
+    {
+        myVoxels->SetSizeRange(myDisplayedXMin, myDisplayedXMax,
+                               myDisplayedYMin, myDisplayedYMax,
+                               myDisplayedZMin, myDisplayedZMax);
+    }
+}
+
+void Application::setDisplayedXMax()
+{
+       myDisplayedXMax = QInputDialog::getDouble(this, "Voxel demo-application", "Maximum X value:", myDisplayedXMax);
+    if (!myVoxels.IsNull())
+    {
+        myVoxels->SetSizeRange(myDisplayedXMin, myDisplayedXMax,
+                               myDisplayedYMin, myDisplayedYMax,
+                               myDisplayedZMin, myDisplayedZMax);
+    }
+}
+
+void Application::setDisplayedYMin()
+{
+       myDisplayedYMin = QInputDialog::getDouble(this, "Voxel demo-application", "Minimum Y value:", myDisplayedYMin);
+    if (!myVoxels.IsNull())
+    {
+        myVoxels->SetSizeRange(myDisplayedXMin, myDisplayedXMax,
+                               myDisplayedYMin, myDisplayedYMax,
+                               myDisplayedZMin, myDisplayedZMax);
+    }
+}
+
+void Application::setDisplayedYMax()
+{
+       myDisplayedYMax = QInputDialog::getDouble(this, "Voxel demo-application", "Maximum Y value:", myDisplayedYMax);
+    if (!myVoxels.IsNull())
+    {
+        myVoxels->SetSizeRange(myDisplayedXMin, myDisplayedXMax,
+                               myDisplayedYMin, myDisplayedYMax,
+                               myDisplayedZMin, myDisplayedZMax);
+    }
+}
+
+void Application::setDisplayedZMin()
+{
+       myDisplayedZMin = QInputDialog::getDouble(this, "Voxel demo-application", "Minimum Z value:", myDisplayedZMin);
+    if (!myVoxels.IsNull())
+    {
+        myVoxels->SetSizeRange(myDisplayedXMin, myDisplayedXMax,
+                               myDisplayedYMin, myDisplayedYMax,
+                               myDisplayedZMin, myDisplayedZMax);
+    }
+}
+
+void Application::setDisplayedZMax()
+{
+       myDisplayedZMax = QInputDialog::getDouble(this, "Voxel demo-application", "Maximum Z value:", myDisplayedZMax);
+    if (!myVoxels.IsNull())
+    {
+        myVoxels->SetSizeRange(myDisplayedXMin, myDisplayedXMax,
+                               myDisplayedYMin, myDisplayedYMax,
+                               myDisplayedZMin, myDisplayedZMax);
+    }
+}
+
+void Application::setScanSide()
+{
+       myScanSide = 
+               QInputDialog::getInteger(this, "Voxel demo-application", "Side of scanning (1: +X side, 2: +Y side, 3: +Z side, 4: +X & +Y sides, .. 7: +X, +Y,& +Z sides):", 
+                                 myScanSide, 1, 7, 1);
+}
+
+void Application::setVolumicBoolValue()
+{
+       myVolumicBoolValue = 
+               QInputDialog::getInteger(this, "Voxel demo-application", "Volumic value on voxelization [0 .. 1]:", 
+                                 myVolumicBoolValue, 0, 1, 1);
+}
+
+void Application::setVolumicColorValue()
+{
+       myVolumicColorValue = 
+               QInputDialog::getInteger(this, "Voxel demo-application", "Volumic value on voxelization [0 .. 15]:", 
+                                 myVolumicColorValue, 0, 15, 1);
+}
+
+void Application::setQuadrangleSize()
+{
+       myQuadrangleSize = 
+               QInputDialog::getInteger(this, "Voxel demo-application", "Size of quadrangles (0% .. 100%):", 
+                                 myQuadrangleSize, 1, 100, 10);
+    if (!myVoxels.IsNull())
+    {
+        myVoxels->SetQuadrangleSize(myQuadrangleSize);
+    }
+}
+
+void Application::setPointSize()
+{
+       myPointSize = 
+               QInputDialog::getInteger(this, "Voxel demo-application", "Size of points (1 .. 10):", 
+                                 myPointSize, 1, 10, 1);
+    if (!myVoxels.IsNull())
+    {
+        myVoxels->SetPointSize(myPointSize);
+    }
+}
+
+void Application::display(Voxel_VoxelDisplayMode mode)
+{
+    if (myVoxels.IsNull() || !myViewer->getIC()->IsDisplayed(myVoxels))
+    {
+               QMessageBox::warning( this, "Voxel demo-application", "Voxels are not displayed");
+               return;
+       }
+
+    myVoxels->SetDisplayMode(mode);
+
+    if (myColorVoxels)
+        displayColorScale();
+    else
+        myViewer->getView()->ColorScaleErase();
+
+    myViewer->getIC()->Redisplay(myVoxels, true);
+}
+
+void Application::displayPoints()
+{
+    display(Voxel_VDM_POINTS);
+}
+
+void Application::displayNearestPoints()
+{
+    display(Voxel_VDM_NEARESTPOINTS);
+}
+
+void Application::displayBoxes()
+{
+    display(Voxel_VDM_BOXES);
+}
+
+void Application::displayNearestBoxes()
+{
+    display(Voxel_VDM_NEARESTBOXES);
+}
+
+void Application::displayColorScale()
+{
+       Handle(Aspect_ColorScale) color_scale = myViewer->getView()->ColorScale();
+       if (!color_scale.IsNull())
+       {
+        int nb_colors = 1<<4 /* 4 bits */;
+        color_scale->SetRange(0, nb_colors - 1);
+        color_scale->SetNumberOfIntervals(nb_colors);
+               color_scale->SetPosition(0.01, 0.5 - 0.01);
+               color_scale->SetSize(0.5 - 0.01, 0.5 - 0.01);
+       }
+    myViewer->getView()->ColorScaleDisplay();
+}
+
+void Application::displayWaves()
+{
+    myViewer->getIC()->EraseAll(false, false);
+
+    // Make voxels
+    if (myBoolVoxels)
+    {
+        delete myBoolVoxels;
+        myBoolVoxels = 0;
+    }
+    if (myColorVoxels)
+        delete myColorVoxels;
+
+    int nbx = 500, nby = 50, nbz = 50;
+    double xlen = 100.0, ylen = 100.0, zlen = 20.0;
+    double dx = xlen / (double) nbx, dy = ylen / (double) nby, dz = zlen / (double) nbz;
+    myColorVoxels = new Voxel_ColorDS(0.0, 0.0, 0.0, xlen, ylen, zlen, nbx, nby, nbz);
+
+    // Initial state - no colors
+    int ix, iy, iz;
+    for (ix = 0; ix < nbx; ix++)
+    {
+        for (iy = 0; iy < nby; iy++)
+        {
+            for (iz = 0; iz < nbz; iz++)
+            {
+                myColorVoxels->Set(ix, iy, iz, 0);
+            }
+        }
+    }
+
+    // Init visual data
+    initPrs();
+    myVoxels->SetDisplayMode(Voxel_VDM_POINTS);
+    myVoxels->SetUsageOfGLlists(false);
+       myVoxels->SetBoolVoxels(myBoolVoxels);
+       myVoxels->SetColorVoxels(myColorVoxels);
+    if (myViewer->getIC()->IsDisplayed(myVoxels))
+        myViewer->getIC()->Redisplay(myVoxels, false);
+    else
+           myViewer->getIC()->Display(myVoxels, false);
+    myViewer->getView()->FitAll();
+
+    // Prepare arrays of values
+    // X&Z values
+    int i = 0, di = 5 /* nb waves */;
+    int* zvalues = new int[nbx];
+    unsigned char* xvalues = new unsigned char[nbx];
+    for (ix = 0; ix < nbx; ix++, i += di)
+    {
+        if (i > nbx || i < 0)
+        {
+            di *= -1;
+            i += di;
+        }
+        double rad = -M_PI / 2.0 + double(i) / (double) nbx * M_PI;
+        double c = cos(rad);
+        xvalues[ix] = 15.0 * c;
+        if (xvalues[ix] == 0)
+            xvalues[ix] = 1;
+        zvalues[ix] = (nbz - 2) * c;
+    }
+
+    // Make waves
+    unsigned char value = 0;
+    for (i = 0; i <= 100; i++)
+    {
+        for (ix = 0; ix < nbx; ix++)
+        {
+            int ixi = ix + i;
+            if (ixi >= nbx)
+                ixi -= nbx;
+            for (iz = 0; iz < nbz; iz++)
+            {
+                value = 0;
+                if (iz < zvalues[ixi])
+                    value = xvalues[ixi];
+                for (iy = 0; iy < nby; iy++)
+                {
+                    myColorVoxels->Set(ix, iy, iz, value);
+                }
+            }
+        }
+        myViewer->getIC()->Redisplay(myVoxels, true);
+        qApp->processEvents();
+    }
+
+    delete[] xvalues;
+    delete[] zvalues;
+}
+
+void Application::initPrs()
+{
+       if (myVoxels.IsNull())
+    {
+               myVoxels = new Voxel_Prs;
+        myVoxels->SetDisplayMode(Voxel_VDM_POINTS);
+        myVoxels->SetColor(Quantity_NOC_WHITE);
+        myVoxels->SetPointSize(1.0);
+        myVoxels->SetSmoothPoints(false);
+        myVoxels->SetQuadrangleSize(myQuadrangleSize);
+        myVoxels->SetColorRange(myColorMinValue, myColorMaxValue);
+        // Colors of ColorDS
+        int nb_colors = 16 /* 4 bits */;
+        Handle(Quantity_HArray1OfColor) colors = new Quantity_HArray1OfColor(0, nb_colors - 1);
+        for (int icolor = 0; icolor < nb_colors; icolor++)
+        {
+            Quantity_Color color;
+            Aspect_ColorScale::FindColor(icolor, 0, nb_colors - 1, nb_colors, color);
+            colors->SetValue(icolor, color);
+        }
+        myVoxels->SetColors(colors);
+        myViewer->setPrs(myVoxels);
+    }
+    else
+    {
+        myViewer->getIC()->RecomputePrsOnly(myVoxels, false);
+    }
+}
+
+void Application::box()
+{
+    gp_Ax2 axes(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1));
+    TopoDS_Shape S = BRepPrimAPI_MakeBox(axes, 100, 100, 100);
+    load(S);
+}
+
+void Application::cylinder()
+{
+    TopoDS_Shape S = BRepPrimAPI_MakeCylinder(50, 100);
+    load(S);
+}
+
+void Application::torus()
+{
+    TopoDS_Shape S = BRepPrimAPI_MakeTorus(100, 20);
+    load(S);
+}
+
+void Application::sphere()
+{
+    TopoDS_Shape S = BRepPrimAPI_MakeSphere(100);
+    load(S);
+}
+
+void Application::load(const TopoDS_Shape& S)
+{
+       myViewer->getIC()->EraseAll(false, false);
+
+    // Delete voxels of previous shape.
+    if (myBoolVoxels)
+    {
+        delete myBoolVoxels;
+        myBoolVoxels = 0;
+    }
+    if (myColorVoxels)
+    {
+        delete myColorVoxels;
+        myColorVoxels = 0;
+    }
+    
+    // Set view size
+    Bnd_Box box;
+    double xmin, ymin, zmin, xmax, ymax, zmax, length = 0;
+    BRepBndLib::Add(S, box);
+    box.Get(xmin, ymin, zmin, xmax, ymax, zmax);
+    length = xmax - xmin > ymax - ymin ? xmax - xmin : ymax - ymin;
+    length = length > zmax - zmin ? length : zmax - zmin;
+    length *= 2.0;
+    myViewer->getView()->SetSize(length);
+    myViewer->getView()->SetZSize(length);
+
+    // Display shape
+       if (myShape.IsNull())
+       {
+               myShape = new AIS_Shape(S);
+               myShape->SetDisplayMode(1);
+        myShape->UnsetSelectionMode();
+       }
+       else
+       {
+               myShape->Set(S);
+        myViewer->getIC()->RecomputePrsOnly(myShape, false);
+       }
+    if (myViewer->getIC()->IsDisplayed(myShape))
+        myViewer->getIC()->Redisplay(myShape, false);
+    else
+           myViewer->getIC()->Display(myShape, false);
+       myViewer->getView()->FitAll();
+}
+
+void Application::displayCut()
+{
+    myViewer->getIC()->EraseAll(false, false);
+
+    // Make a sphere with a lot of toruses, 
+    // cut the toruses from the sphere.
+    TopoDS_Shape sphere = BRepPrimAPI_MakeSphere(100.0);
+    TopoDS_Shape torus1 = BRepPrimAPI_MakeTorus(gp_Ax2(gp_Pnt( 80,   0, 20), gp::DZ()), 30, 10);
+    TopoDS_Shape torus2 = BRepPrimAPI_MakeTorus(gp_Ax2(gp_Pnt(  0,  80, 20), gp::DZ()), 30, 10);
+    TopoDS_Shape torus3 = BRepPrimAPI_MakeTorus(gp_Ax2(gp_Pnt(-80,   0, 20), gp::DZ()), 30, 10);
+    TopoDS_Shape torus4 = BRepPrimAPI_MakeTorus(gp_Ax2(gp_Pnt(  0, -80, 20), gp::DZ()), 30, 10);
+
+    // Compute bounding box of the shapes
+    Bnd_Box box;
+    BRepBndLib::Add(sphere, box);
+    BRepBndLib::Add(torus1, box);
+    BRepBndLib::Add(torus2, box);
+    BRepBndLib::Add(torus3, box);
+    BRepBndLib::Add(torus4, box);
+
+    // Nullify voxels
+    if (myColorVoxels)
+    {
+        delete myColorVoxels;
+        myColorVoxels = 0;
+    }
+    if (myBoolVoxels)
+    {
+        delete myBoolVoxels;
+        myBoolVoxels = 0;
+    }
+
+    Timer timer;
+    timer.Start();
+
+    // Create a cube of voxels
+    int nbx = 100, nby = 100, nbz = 100;
+    double xmin, ymin, zmin, xmax, ymax, zmax;
+    box.Get(xmin, ymin, zmin, xmax, ymax, zmax);
+    myColorVoxels = new Voxel_ColorDS(xmin, ymin, zmin, 
+                                      xmax - xmin, ymax - ymin, zmax - zmin,
+                                      nbx, nby, nbz);
+    Voxel_ColorDS vtorus(xmin, ymin, zmin, 
+                         xmax - xmin, ymax - ymin, zmax - zmin,
+                         nbx, nby, nbz);
+
+    // Make a cube of voxels for the sphere.
+    int progress;
+    Voxel_FastConverter converter(sphere, *myColorVoxels, 0.1, nbx, nby, nbz);
+    converter.Convert(progress);
+    converter.FillInVolume(15);
+   
+    // Torus 1
+    Voxel_FastConverter converter1(torus1, vtorus, 0.1, nbx, nby, nbz);
+    converter1.Convert(progress);
+    converter1.FillInVolume(3);
+   
+    // Torus 2
+    Voxel_FastConverter converter2(torus2, vtorus, 0.1, nbx, nby, nbz);
+    converter2.Convert(progress);
+    converter2.FillInVolume(7);
+   
+    // Torus 3
+    Voxel_FastConverter converter3(torus3, vtorus, 0.1, nbx, nby, nbz);
+    converter3.Convert(progress);
+    converter3.FillInVolume(10);
+   
+    // Torus 4
+    Voxel_FastConverter converter4(torus4, vtorus, 0.1, nbx, nby, nbz);
+    converter4.Convert(progress);
+    converter4.FillInVolume(12);
+
+    // Cut
+    Voxel_BooleanOperation cutter;
+    cutter.Cut(*myColorVoxels, vtorus);
+
+    // Remove volumic voxels
+    converter.FillInVolume(0);
+
+    timer.Stop();
+    timer.Print("Cut");
+
+    // Display
+    initPrs();
+    myVoxels->SetDisplayMode(Voxel_VDM_POINTS);
+    myVoxels->SetUsageOfGLlists(true);
+       myVoxels->SetBoolVoxels(myBoolVoxels);
+       myVoxels->SetColorVoxels(myColorVoxels);
+    if (myViewer->getIC()->IsDisplayed(myVoxels))
+        myViewer->getIC()->Redisplay(myVoxels, false);
+    else
+           myViewer->getIC()->Display(myVoxels, false);
+    myViewer->getView()->FitAll();
+}
+
+void Application::displayCollisions()
+{
+    myViewer->getIC()->EraseAll(false, false);
+
+    // Make a big box with a lot of small spheres inside.
+    double x = 0.0, y = 0.0, z = 0.0, xlen = 100.0, ylen = 100.0, zlen = 100.0, r = 10.0;
+    gp_Pnt P1(x, y, z); // center point of moving sphere (S1).
+    TopoDS_Shape B   = BRepPrimAPI_MakeBox(gp_Pnt(x-r, y-r, z-r), gp_Pnt(xlen+r, ylen+r, zlen+r));
+    TopoDS_Shape S1  = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(x,       y,       z),       gp::DZ()), r / 2.0);
+    TopoDS_Shape S2  = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen/2., y,       z),       gp::DZ()), r);
+    TopoDS_Shape S3  = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen,    y,       z),       gp::DZ()), r);
+    TopoDS_Shape S4  = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(x,       ylen/2., z),       gp::DZ()), r);
+    TopoDS_Shape S5  = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen/2., ylen/2., z),       gp::DZ()), r);
+    TopoDS_Shape S6  = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen,    ylen/2., z),       gp::DZ()), r);
+    TopoDS_Shape S7  = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(x,       ylen,    z),       gp::DZ()), r);
+    TopoDS_Shape S8  = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen/2., ylen,    z),       gp::DZ()), r);
+    TopoDS_Shape S9  = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen,    ylen,    z),       gp::DZ()), r);
+    TopoDS_Shape S10 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(x,       y,       zlen/2.), gp::DZ()), r);
+    TopoDS_Shape S11 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen/2., y,       zlen/2.), gp::DZ()), r);
+    TopoDS_Shape S12 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen,    y,       zlen/2.), gp::DZ()), r);
+    TopoDS_Shape S13 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(x,       ylen/2., zlen/2.), gp::DZ()), r);
+    TopoDS_Shape S14 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen/2., ylen/2., zlen/2.), gp::DZ()), r);
+    TopoDS_Shape S15 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen,    ylen/2., zlen/2.), gp::DZ()), r);
+    TopoDS_Shape S16 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(x,       ylen,    zlen/2.), gp::DZ()), r);
+    TopoDS_Shape S17 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen/2., ylen,    zlen/2.), gp::DZ()), r);
+    TopoDS_Shape S18 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen,    ylen,    zlen/2.), gp::DZ()), r);
+    TopoDS_Shape S19 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(x,       y,       zlen),    gp::DZ()), r);
+    TopoDS_Shape S20 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen/2., y,       zlen),    gp::DZ()), r);
+    TopoDS_Shape S21 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen,    y,       zlen),    gp::DZ()), r);
+    TopoDS_Shape S22 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(x,       ylen/2., zlen),    gp::DZ()), r);
+    TopoDS_Shape S23 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen/2., ylen/2., zlen),    gp::DZ()), r);
+    TopoDS_Shape S24 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen,    ylen/2., zlen),    gp::DZ()), r);
+    TopoDS_Shape S25 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(x,       ylen,    zlen),    gp::DZ()), r);
+    TopoDS_Shape S26 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen/2., ylen,    zlen),    gp::DZ()), r);
+    TopoDS_Shape S27 = BRepPrimAPI_MakeSphere(gp_Ax2(gp_Pnt(xlen,    ylen,    zlen),    gp::DZ()), r);
+
+    // Planes of the big box
+    gp_Ax2 xminusPlane(gp_Pnt(x,    y,    z),    gp::DX());
+    gp_Ax2 xplusPlane (gp_Pnt(xlen, y,    z),    gp::DX());
+    gp_Ax2 yminusPlane(gp_Pnt(x,    y,    z),    gp::DY());
+    gp_Ax2 yplusPlane (gp_Pnt(x,    ylen, z),    gp::DY());
+    gp_Ax2 zminusPlane(gp_Pnt(x,    y,    z),    gp::DZ());
+    gp_Ax2 zplusPlane (gp_Pnt(x,    y,    zlen), gp::DZ());
+
+    // Nullify voxels
+    if (myColorVoxels)
+    {
+        delete myColorVoxels;
+        myColorVoxels = 0;
+    }
+    if (myBoolVoxels)
+    {
+        delete myBoolVoxels;
+        myBoolVoxels = 0;
+    }
+
+    // Prepare visualization
+    initPrs();
+    myVoxels->SetDisplayMode(Voxel_VDM_POINTS);
+    myVoxels->SetColor(Quantity_NOC_RED);
+    myVoxels->SetPointSize(4);
+    myVoxels->SetSmoothPoints(false);
+    myVoxels->SetUsageOfGLlists(false);
+       myVoxels->SetColorVoxels(myColorVoxels);
+
+    // Display all shapes
+    double transparency = 0.9;
+    Handle(AIS_Shape) aisB   = new AIS_Shape(B);
+    Handle(AIS_Shape) aisS1  = new AIS_Shape(S1);
+    Handle(AIS_Shape) aisS2  = new AIS_Shape(S2);
+    Handle(AIS_Shape) aisS3  = new AIS_Shape(S3);
+    Handle(AIS_Shape) aisS4  = new AIS_Shape(S4);
+    Handle(AIS_Shape) aisS5  = new AIS_Shape(S5);
+    Handle(AIS_Shape) aisS6  = new AIS_Shape(S6);
+    Handle(AIS_Shape) aisS7  = new AIS_Shape(S7);
+    Handle(AIS_Shape) aisS8  = new AIS_Shape(S8);
+    Handle(AIS_Shape) aisS9  = new AIS_Shape(S9);
+    Handle(AIS_Shape) aisS10 = new AIS_Shape(S10);
+    Handle(AIS_Shape) aisS11 = new AIS_Shape(S11);
+    Handle(AIS_Shape) aisS12 = new AIS_Shape(S12);
+    Handle(AIS_Shape) aisS13 = new AIS_Shape(S13);
+    Handle(AIS_Shape) aisS14 = new AIS_Shape(S14);
+    Handle(AIS_Shape) aisS15 = new AIS_Shape(S15);
+    Handle(AIS_Shape) aisS16 = new AIS_Shape(S16);
+    Handle(AIS_Shape) aisS17 = new AIS_Shape(S17);
+    Handle(AIS_Shape) aisS18 = new AIS_Shape(S18);
+    Handle(AIS_Shape) aisS19 = new AIS_Shape(S19);
+    Handle(AIS_Shape) aisS20 = new AIS_Shape(S20);
+    Handle(AIS_Shape) aisS21 = new AIS_Shape(S21);
+    Handle(AIS_Shape) aisS22 = new AIS_Shape(S22);
+    Handle(AIS_Shape) aisS23 = new AIS_Shape(S23);
+    Handle(AIS_Shape) aisS24 = new AIS_Shape(S24);
+    Handle(AIS_Shape) aisS25 = new AIS_Shape(S25);
+    Handle(AIS_Shape) aisS26 = new AIS_Shape(S26);
+    Handle(AIS_Shape) aisS27 = new AIS_Shape(S27);
+    aisS1-> SetDisplayMode(1);
+    aisS2-> SetDisplayMode(1);
+    aisS3-> SetDisplayMode(1);
+    aisS4-> SetDisplayMode(1);
+    aisS5-> SetDisplayMode(1);
+    aisS6-> SetDisplayMode(1);
+    aisS7-> SetDisplayMode(1);
+    aisS8-> SetDisplayMode(1);
+    aisS9-> SetDisplayMode(1);
+    aisS10->SetDisplayMode(1);
+    aisS11->SetDisplayMode(1);
+    aisS12->SetDisplayMode(1);
+    aisS13->SetDisplayMode(1);
+    aisS14->SetDisplayMode(1);
+    aisS15->SetDisplayMode(1);
+    aisS16->SetDisplayMode(1);
+    aisS17->SetDisplayMode(1);
+    aisS18->SetDisplayMode(1);
+    aisS19->SetDisplayMode(1);
+    aisS20->SetDisplayMode(1);
+    aisS21->SetDisplayMode(1);
+    aisS22->SetDisplayMode(1);
+    aisS23->SetDisplayMode(1);
+    aisS24->SetDisplayMode(1);
+    aisS25->SetDisplayMode(1);
+    aisS26->SetDisplayMode(1);
+    aisS27->SetDisplayMode(1);
+    aisB->  UnsetSelectionMode();
+    aisS1-> UnsetSelectionMode();
+    aisS2-> UnsetSelectionMode();
+    aisS3-> UnsetSelectionMode();
+    aisS4-> UnsetSelectionMode();
+    aisS5-> UnsetSelectionMode();
+    aisS6-> UnsetSelectionMode();
+    aisS7-> UnsetSelectionMode();
+    aisS8-> UnsetSelectionMode();
+    aisS9-> UnsetSelectionMode();
+    aisS10->UnsetSelectionMode();
+    aisS11->UnsetSelectionMode();
+    aisS12->UnsetSelectionMode();
+    aisS13->UnsetSelectionMode();
+    aisS14->UnsetSelectionMode();
+    aisS15->UnsetSelectionMode();
+    aisS16->UnsetSelectionMode();
+    aisS17->UnsetSelectionMode();
+    aisS18->UnsetSelectionMode();
+    aisS19->UnsetSelectionMode();
+    aisS20->UnsetSelectionMode();
+    aisS21->UnsetSelectionMode();
+    aisS22->UnsetSelectionMode();
+    aisS23->UnsetSelectionMode();
+    aisS24->UnsetSelectionMode();
+    aisS25->UnsetSelectionMode();
+    aisS26->UnsetSelectionMode();
+    aisS27->UnsetSelectionMode();
+    aisS1-> SetTransparency(2.0 * transparency / 3.0);
+    aisS2-> SetTransparency(transparency);
+    aisS3-> SetTransparency(transparency);
+    aisS4-> SetTransparency(transparency);
+    aisS5-> SetTransparency(transparency);
+    aisS6-> SetTransparency(transparency);
+    aisS7-> SetTransparency(transparency);
+    aisS8-> SetTransparency(transparency);
+    aisS9-> SetTransparency(transparency);
+    aisS10->SetTransparency(transparency);
+    aisS11->SetTransparency(transparency);
+    aisS12->SetTransparency(transparency);
+    aisS13->SetTransparency(transparency);
+    aisS14->SetTransparency(transparency);
+    aisS15->SetTransparency(transparency);
+    aisS16->SetTransparency(transparency);
+    aisS17->SetTransparency(transparency);
+    aisS18->SetTransparency(transparency);
+    aisS19->SetTransparency(transparency);
+    aisS20->SetTransparency(transparency);
+    aisS21->SetTransparency(transparency);
+    aisS22->SetTransparency(transparency);
+    aisS23->SetTransparency(transparency);
+    aisS24->SetTransparency(transparency);
+    aisS25->SetTransparency(transparency);
+    aisS26->SetTransparency(transparency);
+    aisS27->SetTransparency(transparency);
+    myViewer->getIC()->Display(aisB, false);
+    myViewer->getIC()->Display(aisS1, false);
+    myViewer->getIC()->Display(aisS2, false);
+    myViewer->getIC()->Display(aisS3, false);
+    myViewer->getIC()->Display(aisS4, false);
+    myViewer->getIC()->Display(aisS5, false);
+    myViewer->getIC()->Display(aisS6, false);
+    myViewer->getIC()->Display(aisS7, false);
+    myViewer->getIC()->Display(aisS8, false);
+    myViewer->getIC()->Display(aisS9, false);
+    myViewer->getIC()->Display(aisS10, false);
+    myViewer->getIC()->Display(aisS11, false);
+    myViewer->getIC()->Display(aisS12, false);
+    myViewer->getIC()->Display(aisS13, false);
+    myViewer->getIC()->Display(aisS14, false);
+    myViewer->getIC()->Display(aisS15, false);
+    myViewer->getIC()->Display(aisS16, false);
+    myViewer->getIC()->Display(aisS17, false);
+    myViewer->getIC()->Display(aisS18, false);
+    myViewer->getIC()->Display(aisS19, false);
+    myViewer->getIC()->Display(aisS20, false);
+    myViewer->getIC()->Display(aisS21, false);
+    myViewer->getIC()->Display(aisS22, false);
+    myViewer->getIC()->Display(aisS23, false);
+    myViewer->getIC()->Display(aisS24, false);
+    myViewer->getIC()->Display(aisS25, false);
+    myViewer->getIC()->Display(aisS26, false);
+    myViewer->getIC()->Display(aisS27, false);
+
+    // Prepare computer of collisions
+    double deflection = 0.1;
+    int nbx = 100, nby = 100, nbz = 100;
+    
+    Voxel_CollisionDetection coldet(deflection, nbx, nby, nbz);
+    coldet.SetUsageOfVolume(false);
+    coldet.KeepCollisions(false);
+    coldet.AddShape(S1);
+    coldet.AddShape(S2);
+    coldet.AddShape(S3);
+    coldet.AddShape(S4);
+    coldet.AddShape(S5);
+    coldet.AddShape(S6);
+    coldet.AddShape(S7);
+    coldet.AddShape(S8);
+    coldet.AddShape(S9);
+    coldet.AddShape(S10);
+    coldet.AddShape(S11);
+    coldet.AddShape(S12);
+    coldet.AddShape(S13);
+    coldet.AddShape(S14);
+    coldet.AddShape(S15);
+    coldet.AddShape(S16);
+    coldet.AddShape(S17);
+    coldet.AddShape(S18);
+    coldet.AddShape(S19);
+    coldet.AddShape(S20);
+    coldet.AddShape(S21);
+    coldet.AddShape(S22);
+    coldet.AddShape(S23);
+    coldet.AddShape(S24);
+    coldet.AddShape(S25);
+    coldet.AddShape(S26);
+    coldet.AddShape(S27);
+    //coldet.AddShape(BRepPrimAPI_MakeBox(gp_Pnt(x, y, z), gp_Pnt(xlen, ylen, zlen)));
+    
+    Bnd_Box box;
+    BRepBndLib::Add(B, box);
+    coldet.SetBoundaryBox(box);
+
+    coldet.Voxelize();
+
+    // Move one of the spheres inside the box
+    // and compute collisions
+    gp_Trsf trsf;
+    gp_Vec vmove(1, 0.5, 0.25);
+
+    int imove = 0, nb_moves = 900;
+    while (imove < nb_moves)
+    {
+        // Move
+        trsf.SetTranslation(vmove);
+        TopLoc_Location loc(trsf);
+        S1.Move(loc);
+        P1.Translate(vmove);
+        
+        // Check whether S1 is inside the big box
+        // Detect the plane S1 touches to.
+        if (P1.X() < x)
+            vmove.Mirror(xminusPlane);
+        else if (P1.X() > xlen)
+            vmove.Mirror(xplusPlane);
+        else if (P1.Y() < y)
+            vmove.Mirror(yminusPlane);
+        else if (P1.Y() > ylen)
+            vmove.Mirror(yplusPlane);
+        else if (P1.Z() < z)
+            vmove.Mirror(zminusPlane);
+        else if (P1.Z() > zlen)
+            vmove.Mirror(zplusPlane);
+
+        // Compute collisions
+        coldet.ReplaceShape(1, S1);
+        coldet.Voxelize(1); // only the first sphere (S1)
+        coldet.Compute();
+        myBoolVoxels = &((Voxel_BoolDS&) coldet.GetCollisions());
+
+        // Redisplay S1
+        aisS1->Set(S1);
+        myViewer->getIC()->Redisplay(aisS1, false);
+
+        // Display the collisions
+        myVoxels->SetBoolVoxels(myBoolVoxels);
+        if (myViewer->getIC()->IsDisplayed(myVoxels))
+            myViewer->getIC()->Redisplay(myVoxels, true);
+        else
+        {
+               myViewer->getIC()->Display(myVoxels, false);
+            myViewer->getView()->FitAll();
+        }
+
+        imove++;
+        qApp->processEvents();
+    }
+
+    // Copy the result of collision detection
+    int ix, iy, iz;
+    myBoolVoxels = new Voxel_BoolDS(coldet.GetCollisions().GetX(), 
+                                    coldet.GetCollisions().GetY(), 
+                                    coldet.GetCollisions().GetZ(), 
+                                    coldet.GetCollisions().GetXLen(), 
+                                    coldet.GetCollisions().GetYLen(), 
+                                    coldet.GetCollisions().GetZLen(), 
+                                    nbx, nby, nbz);
+    for (ix = 0; ix < nbx; ix++)
+    {
+        for (iy = 0; iy < nby; iy++)
+        {
+            for (iz = 0; iz < nbz; iz++)
+            {
+                if (coldet.GetCollisions().Get(ix, iy, iz))
+                    myBoolVoxels->Set(ix, iy, iz, Standard_True);
+            }
+        }
+    }
+    myVoxels->SetBoolVoxels(myBoolVoxels);
+}
\ No newline at end of file
diff --git a/samples/qt/VoxelDemo/src/ConversionThread.cpp b/samples/qt/VoxelDemo/src/ConversionThread.cpp
new file mode 100644 (file)
index 0000000..6fee824
--- /dev/null
@@ -0,0 +1,58 @@
+#include "ConversionThread.h"
+
+ConversionThread::ConversionThread():QThread(),
+/*myConverter(0),*/myFastConverter(0),
+myVolumicValue(0),myScanSide(1),
+myThreadIndex(1)
+{
+
+}
+
+ConversionThread::~ConversionThread()
+{
+
+}
+
+/*
+void ConversionThread::setConverter(Voxel_Converter* converter)
+{
+    myConverter = converter;
+    myFastConverter = 0;
+}
+*/
+
+void ConversionThread::setConverter(Voxel_FastConverter* converter)
+{
+    myFastConverter = converter;
+    //myConverter = 0;
+}
+
+void ConversionThread::setVolumicValue(const int value)
+{
+    myVolumicValue = value;
+}
+
+void ConversionThread::setScanSide(const int side)
+{
+    myScanSide = side;
+}
+
+void ConversionThread::setThreadIndex(const int ithread)
+{
+    myThreadIndex = ithread;
+}
+
+int* ConversionThread::getProgress()
+{
+    return &myProgress;
+}
+
+void ConversionThread::run()
+{
+    if (/*!myConverter && */!myFastConverter)
+        return;
+    //if (myConverter)
+    //    myConverter->Convert(myProgress, myVolumicValue, myScanSide, myThreadIndex);
+    //else
+        myFastConverter->Convert(myProgress, myThreadIndex);
+}
diff --git a/samples/qt/VoxelDemo/src/Main.cpp b/samples/qt/VoxelDemo/src/Main.cpp
new file mode 100644 (file)
index 0000000..e5f9175
--- /dev/null
@@ -0,0 +1,13 @@
+#include <qapplication.h>
+#include "application.h"
+
+int main( int argc, char ** argv ) 
+{
+    QApplication a( argc, argv );
+
+    Application *w = new Application();
+    w->setWindowTitle( "Voxel demo-application" );
+    w->show();
+    a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
+    return a.exec();
+}
diff --git a/samples/qt/VoxelDemo/src/Timer.cpp b/samples/qt/VoxelDemo/src/Timer.cpp
new file mode 100644 (file)
index 0000000..d8a3f3e
--- /dev/null
@@ -0,0 +1,67 @@
+// Timer.cpp: implementation of the Timer class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "Timer.h"
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+Timer::Timer():myWriter(0) {}
+
+Timer::Timer(const char* filename)
+{
+       myWriter = fopen(filename, "a");
+}
+
+Timer::~Timer()
+{
+       if (myWriter)
+               fclose(myWriter);
+}
+
+void Timer::Start() {
+       myTimer.Reset();
+       myTimer.Start();
+}
+
+void Timer::Stop() {
+       myTimer.Stop();
+}
+
+void Timer::Continue() {
+       myTimer.Start();
+}
+
+void Timer::Reset() {
+       myTimer.Reset();
+}
+
+float Timer::Seconds() {
+  Standard_Real sec, cpu;
+  Standard_Integer minutes, hours;
+  myTimer.Show(sec, minutes, hours, cpu);
+  return (float) sec;
+}
+
+int Timer::Minutes() {
+  Standard_Real sec, cpu;
+  Standard_Integer minutes, hours;
+  myTimer.Show(sec, minutes, hours, cpu);
+  return minutes;
+}
+
+void Timer::Print(char* label) {
+       Standard_Real seconds, cpu;
+       Standard_Integer minutes, hours;
+       myTimer.Show(seconds, minutes, hours, cpu);
+       if (myWriter)
+       {
+               fprintf(myWriter, "%s took %d minutes %g seconds\n", label, minutes, seconds);
+       }
+       else
+       {
+               cout<<label<<" took "<<minutes<<" minutes, "<<seconds<<" seconds"<<endl;
+       }
+}
\ No newline at end of file
diff --git a/samples/qt/VoxelDemo/src/Viewer.cpp b/samples/qt/VoxelDemo/src/Viewer.cpp
new file mode 100644 (file)
index 0000000..d0304bf
--- /dev/null
@@ -0,0 +1,207 @@
+#include "Viewer.h"
+#include "Timer.h"
+
+#include <QApplication.h>
+#include <QCursor.h>
+#include <QMessagebox.h>
+
+#include <QMouseEvent>
+
+#include <WNT_Window.hxx>
+#include <Graphic3d_WNTGraphicDevice.hxx>
+
+#include <Voxel_Prs.hxx>
+#include <AIS_ListOfInteractive.hxx>
+#include <AIS_ListIteratorOfListOfInteractive.hxx>
+
+static Handle(Graphic3d_WNTGraphicDevice) device;
+
+Viewer::Viewer(QWidget* parent):QWidget(parent)
+{
+    if(device.IsNull())
+        device = new Graphic3d_WNTGraphicDevice();
+    
+               Handle(V3d_Viewer) aViewer = new V3d_Viewer(device, TCollection_ExtendedString("Visu3D").ToExtString(), "",
+                                                1000, V3d_XposYnegZpos,
+                                                Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
+                                                true, true, V3d_TEX_NONE);
+    aViewer->Init();
+
+       aViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
+
+    myView = aViewer->CreateView();
+    myIC = new AIS_InteractiveContext(aViewer);
+    myIC->SetDeviationCoefficient(1.e-3);
+
+    int       windowHandle = (int) winId();
+    short     hi, lo;
+
+    lo = (short) windowHandle;
+    hi = (short) (windowHandle >> 16);
+    Handle(WNT_Window) hWnd =
+        new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(aViewer->Device()), (int) hi, (int) lo);
+
+    myView->SetWindow(hWnd);
+    if(!hWnd->IsMapped())
+        hWnd->Map();
+
+    myView->MustBeResized();
+    myView->SetSurfaceDetail(V3d_TEX_NONE);
+    myView->SetTransparency(Standard_True);
+    myView->SetSize(10000.0);
+    myView->SetZSize(10000.0);
+    myView->SetViewMappingDefault();
+
+    myZoom = false;
+    myPan = false;
+    myRotate = false;
+    setMouseTracking(true);
+
+    setMinimumSize(400, 200);
+    
+    myView->ZBufferTriedronSetup();
+    myView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_BLACK, 0.1, V3d_ZBUFFER);
+
+    mySelector.Init(myView);
+
+       setBackgroundRole( QPalette::NoRole );//NoBackground );
+       // set focus policy to threat QContextMenuEvent from keyboard  
+       setFocusPolicy( Qt::StrongFocus );
+       setAttribute( Qt::WA_PaintOnScreen );
+       setAttribute( Qt::WA_NoSystemBackground );
+}
+
+Viewer::~Viewer()
+{
+
+}
+
+void Viewer::paintEvent(QPaintEvent * pEvent)
+{
+    if (!myView.IsNull())
+        myView->Redraw();
+}
+
+
+/*!
+  Get paint engine for the OpenGL viewer. [ virtual public ]
+*/
+QPaintEngine* Viewer::paintEngine() const
+{
+  return 0;
+}
+
+void Viewer::resizeEvent(QResizeEvent * e)
+{
+    if (!myView.IsNull())
+    {
+        myView->MustBeResized();
+    }
+}
+
+void Viewer::mousePressEvent(QMouseEvent * mpEvent)
+{
+    // Memorize start point
+    myStartPnt.setX(mpEvent->x());
+    myStartPnt.setY(mpEvent->y());
+    
+    // Inform IC that the mouse cursor is at the point
+    myIC->MoveTo(myStartPnt.x(), myStartPnt.y(), myView);
+
+    // In case of rotation, define the start rotation point
+    if ((mpEvent->modifiers() & Qt::ControlModifier) && (mpEvent->buttons() & Qt::RightButton))
+    {
+        myView->StartRotation(myStartPnt.x(), myStartPnt.y());
+    }
+
+    // Start degenerate mode
+    setDegenerateMode(true);
+
+    emit mousePressed(mpEvent->modifiers(), mpEvent->x(), mpEvent->y());
+}
+
+void Viewer::mouseMoveEvent(QMouseEvent * mmEvent)
+{
+    QPoint currentPnt(mmEvent->x(), mmEvent->y());
+
+    if (mmEvent->modifiers() & Qt::ControlModifier)
+    {
+        if (mmEvent->buttons() & Qt::LeftButton)
+        {
+            myView->Zoom(myStartPnt.x(), myStartPnt.y(), currentPnt.x(), currentPnt.y());
+            myStartPnt = currentPnt;
+        }
+        else if (mmEvent->buttons() & Qt::MidButton)
+        {
+            myView->Pan(currentPnt.x() - myStartPnt.x(), myStartPnt.y() - currentPnt.y());
+            myStartPnt = currentPnt;
+        }
+        else if (mmEvent->buttons() & Qt::RightButton)
+        {
+            myView->Rotation(currentPnt.x(), currentPnt.y());
+        }
+    }
+    else
+    {
+        myIC->MoveTo(currentPnt.x(), currentPnt.y(), myView);
+    }
+
+    emit mouseMoved(mmEvent->modifiers(), currentPnt.x(), currentPnt.y());
+}
+
+void Viewer::mouseReleaseEvent(QMouseEvent * mrEvent)
+{
+    if(mrEvent->button() == Qt::LeftButton)
+    {
+        if(!myZoom && !myPan && !myRotate)
+        {
+            if(mrEvent->modifiers() & Qt::ShiftModifier)
+                myIC->ShiftSelect();
+            else
+                myIC->Select();
+
+            // Select a voxel
+            int ix = -1, iy = -1, iz = -1;
+            bool detected = mySelector.Detect(mrEvent->x(), mrEvent->y(), ix, iy, iz);
+            if (detected)
+            {
+                cout<<"("<<ix<<", "<<iy<<", "<<iz<<")"<<endl;
+            }
+            if (!myPrs.IsNull())
+                myPrs->Highlight(ix, iy, iz);
+        }
+    }
+    else if(mrEvent->button() == Qt::RightButton)
+    {
+        // Popup menu:
+
+    
+       }
+
+    // Finish degenerate mode
+    setDegenerateMode(false);
+    
+    emit mouseReleased(mrEvent->modifiers(), mrEvent->x(), mrEvent->y());
+}
+
+void Viewer::mouseDoubleClickEvent(QMouseEvent * mdcEvent)
+{
+    emit mouseDoubleClick(mdcEvent->modifiers(), mdcEvent->x(), mdcEvent->y());
+}
+
+void Viewer::setDegenerateMode(const bool on)
+{
+    AIS_ListOfInteractive displayed;
+    myIC->DisplayedObjects(displayed);
+    AIS_ListIteratorOfListOfInteractive itri(displayed);
+    for (; itri.More(); itri.Next())
+    {
+        if (itri.Value()->DynamicType() == STANDARD_TYPE(Voxel_Prs))
+        {
+            Handle(Voxel_Prs) prs = Handle(Voxel_Prs)::DownCast(itri.Value());
+            prs->SetDegenerateMode(on);
+            myView->Redraw();
+            break;
+        }
+    }
+}
diff --git a/samples/qt/VoxelDemo/src/VoxelClient_VisDrawer.cxx b/samples/qt/VoxelDemo/src/VoxelClient_VisDrawer.cxx
new file mode 100644 (file)
index 0000000..e75fbc7
--- /dev/null
@@ -0,0 +1,3373 @@
+// Copyright (c) 1999-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
+#include "VoxelClient_VisDrawer.h"
+
+#include <ElSLib.hxx>
+#include <gp_Dir.hxx>
+#include <Geom_Plane.hxx>
+#include <gce_MakePln.hxx>
+#include <Quantity_Color.hxx>
+#include <Aspect_TypeOfLine.hxx>
+#include <Graphic3d_CUserDraw.hxx>
+
+#include <InterfaceGraphic_telem.hxx>
+#include <OpenGl_Element.hxx>
+#include <OpenGl_Callback.hxx>
+#include <OpenGl_NamedStatus.hxx>
+
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+/**************************************************************************/
+
+class VoxelClient_VisDrawer::VisElement : public OpenGl_Element
+{
+public:
+
+  VisElement (Voxel_VisData*);
+  virtual ~VisElement();
+
+  void EvaluateBounds (Graphic3d_CBounds& theMinMax);
+
+  void Render (const Handle(OpenGl_Workspace) &theWorkspace) const;
+
+private:
+
+  VoxelClient_VisDrawer* myHandler;
+
+public:
+
+  DEFINE_STANDARD_ALLOC
+
+};
+
+//=======================================================================
+//function : VisElement
+//purpose  : Constructor
+//=======================================================================
+
+VoxelClient_VisDrawer::VisElement::VisElement (Voxel_VisData* theData)
+{
+  myHandler = new VoxelClient_VisDrawer (theData);
+}
+
+//=======================================================================
+//function : ~VisElement
+//purpose  : Destructor
+//=======================================================================
+
+VoxelClient_VisDrawer::VisElement::~VisElement ()
+{
+  delete myHandler;
+}
+
+//=======================================================================
+//function : EvaluateBounds
+//purpose  :
+//=======================================================================
+
+void VoxelClient_VisDrawer::VisElement::EvaluateBounds
+  (Graphic3d_CBounds& theMinMax)
+{
+  myHandler->EvalMinMax (theMinMax);
+}
+
+//=======================================================================
+//function : Render
+//purpose  : display element
+//=======================================================================
+
+void VoxelClient_VisDrawer::VisElement::Render
+  (const Handle (OpenGl_Workspace) &theWorkspace) const
+{
+  const Standard_Boolean aHl = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT);
+  myHandler->Display (aHl);
+}
+
+//=======================================================================
+//function : VisDrawerCallBack
+//purpose  : visdrawer element create callback, adds an element to graphic
+//           driver's structure
+//=======================================================================
+
+static OpenGl_Element* VisDrawerCallBack (const Graphic3d_CUserDraw* theUserDraw)
+{
+  if (theUserDraw == 0)
+    return 0;
+
+  // Retrieve the user structure
+  Voxel_VisData* aUserData = (Voxel_VisData*) (theUserDraw->Data);
+
+  if (aUserData == 0)
+    return 0;
+
+  VoxelClient_VisDrawer::VisElement *aElem = 
+    new VoxelClient_VisDrawer::VisElement (aUserData);
+
+  if (theUserDraw->Bounds != 0)
+    aElem->EvaluateBounds (*(theUserDraw->Bounds));
+
+  return aElem;
+}
+
+/**************************************************************************/
+void VoxelClient_VisDrawer::Init()
+{
+    static Standard_Boolean isInitializeded(Standard_False);
+
+    if (!isInitializeded)
+    {
+        isInitializeded = Standard_True;
+
+        OpenGl_UserDrawCallback& aCallback = UserDrawCallback ();
+        aCallback = VisDrawerCallBack;
+    }
+}
+
+/**************************************************************************/
+VoxelClient_VisDrawer::VoxelClient_VisDrawer(Voxel_VisData * theData):myData(theData)
+{
+
+}
+
+/**************************************************************************/
+VoxelClient_VisDrawer::~VoxelClient_VisDrawer()
+{
+    if (myData)
+    {
+        // Because a pointer to the data is copied, 
+        // it is possible to make an attempt to delete GL lists for
+        // a structure, which is already deleted.
+        // Such a situation may happen on close of the application.
+        // Therefore, this try / catch is used.
+
+        try
+        {
+            Standard_Integer idir;
+
+            // Points
+
+            // BoolDS
+            if (myData->myDisplay.myBoolPointsList > 0)
+            {
+                glDeleteLists(myData->myDisplay.myBoolPointsList, 1);
+                myData->myDisplay.myBoolPointsList = -1;
+            }
+            for (idir = Xminus; idir <= Zplus; idir++)
+            {
+                if (myData->myDisplay.myBoolNearestPointsList[idir] > 0)
+                {
+                    glDeleteLists(myData->myDisplay.myBoolNearestPointsList[idir], 1);
+                    myData->myDisplay.myBoolNearestPointsList[idir] = -1;
+                }
+            }
+
+            // ColorDS
+            if (myData->myDisplay.myColorPointsList > 0)
+            {
+                glDeleteLists(myData->myDisplay.myColorPointsList, 1);
+                myData->myDisplay.myColorPointsList = -1;
+            }
+            for (idir = Xminus; idir <= Zplus; idir++)
+            {
+                if (myData->myDisplay.myColorNearestPointsList[idir] > 0)
+                {
+                    glDeleteLists(myData->myDisplay.myColorNearestPointsList[idir], 1);
+                    myData->myDisplay.myColorNearestPointsList[idir] = -1;
+                }
+            }
+
+            // ROctBoolDS
+            if (myData->myDisplay.myROctBoolPointsList > 0)
+            {
+                glDeleteLists(myData->myDisplay.myROctBoolPointsList, 1);
+                myData->myDisplay.myROctBoolPointsList = -1;
+            }
+            for (idir = Xminus; idir <= Zplus; idir++)
+            {
+                if (myData->myDisplay.myROctBoolNearestPointsList[idir] > 0)
+                {
+                    glDeleteLists(myData->myDisplay.myROctBoolNearestPointsList[idir], 1);
+                    myData->myDisplay.myROctBoolNearestPointsList[idir] = -1;
+                }
+            }
+
+            // Triangulation
+            if (myData->myDisplay.myTriangulationList > 0)
+            {
+                glDeleteLists(myData->myDisplay.myTriangulationList, 1);
+                myData->myDisplay.myTriangulationList = -1;
+            }
+        }
+        catch (...)
+        {
+
+        }
+    }
+}
+
+/**************************************************************************/
+void VoxelClient_VisDrawer::EvalMinMax(Graphic3d_CBounds & theMinMax) const 
+{
+    theMinMax.XMin = FLT_MAX;
+    theMinMax.YMin = FLT_MAX;
+    theMinMax.ZMin = FLT_MAX;
+    theMinMax.XMax = -FLT_MAX;
+    theMinMax.YMax = -FLT_MAX;
+    theMinMax.ZMax = -FLT_MAX;
+    if(!myData)
+        return;
+    if(myData->myBoolVoxels)
+    {
+        if (theMinMax.XMin > myData->myBoolVoxels->GetX())
+               theMinMax.XMin = myData->myBoolVoxels->GetX();
+        if (theMinMax.XMax < myData->myBoolVoxels->GetX() + myData->myBoolVoxels->GetXLen())
+               theMinMax.XMax = myData->myBoolVoxels->GetX() + myData->myBoolVoxels->GetXLen();
+        if (theMinMax.YMin > myData->myBoolVoxels->GetY())
+               theMinMax.YMin = myData->myBoolVoxels->GetY();
+        if (theMinMax.YMax < myData->myBoolVoxels->GetY() + myData->myBoolVoxels->GetYLen())
+               theMinMax.YMax = myData->myBoolVoxels->GetY() + myData->myBoolVoxels->GetYLen();
+        if (theMinMax.ZMin > myData->myBoolVoxels->GetZ())
+               theMinMax.ZMin = myData->myBoolVoxels->GetZ();
+        if (theMinMax.ZMax < myData->myBoolVoxels->GetZ() + myData->myBoolVoxels->GetZLen())
+               theMinMax.ZMax = myData->myBoolVoxels->GetZ() + myData->myBoolVoxels->GetZLen();
+    }
+    if(myData->myColorVoxels)
+    {
+        if (theMinMax.XMin > myData->myColorVoxels->GetX())
+               theMinMax.XMin = myData->myColorVoxels->GetX();
+        if (theMinMax.XMax < myData->myColorVoxels->GetX() + myData->myColorVoxels->GetXLen())
+               theMinMax.XMax = myData->myColorVoxels->GetX() + myData->myColorVoxels->GetXLen();
+        if (theMinMax.YMin > myData->myColorVoxels->GetY())
+               theMinMax.YMin = myData->myColorVoxels->GetY();
+        if (theMinMax.YMax < myData->myColorVoxels->GetY() + myData->myColorVoxels->GetYLen())
+               theMinMax.YMax = myData->myColorVoxels->GetY() + myData->myColorVoxels->GetYLen();
+        if (theMinMax.ZMin > myData->myColorVoxels->GetZ())
+               theMinMax.ZMin = myData->myColorVoxels->GetZ();
+        if (theMinMax.ZMax < myData->myColorVoxels->GetZ() + myData->myColorVoxels->GetZLen())
+               theMinMax.ZMax = myData->myColorVoxels->GetZ() + myData->myColorVoxels->GetZLen();
+    }
+    if(myData->myROctBoolVoxels)
+    {
+        if (theMinMax.XMin > myData->myROctBoolVoxels->GetX())
+               theMinMax.XMin = myData->myROctBoolVoxels->GetX();
+        if (theMinMax.XMax < myData->myROctBoolVoxels->GetX() + myData->myROctBoolVoxels->GetXLen())
+               theMinMax.XMax = myData->myROctBoolVoxels->GetX() + myData->myROctBoolVoxels->GetXLen();
+        if (theMinMax.YMin > myData->myROctBoolVoxels->GetY())
+               theMinMax.YMin = myData->myROctBoolVoxels->GetY();
+        if (theMinMax.YMax < myData->myROctBoolVoxels->GetY() + myData->myROctBoolVoxels->GetYLen())
+               theMinMax.YMax = myData->myROctBoolVoxels->GetY() + myData->myROctBoolVoxels->GetYLen();
+        if (theMinMax.ZMin > myData->myROctBoolVoxels->GetZ())
+               theMinMax.ZMin = myData->myROctBoolVoxels->GetZ();
+        if (theMinMax.ZMax < myData->myROctBoolVoxels->GetZ() + myData->myROctBoolVoxels->GetZLen())
+               theMinMax.ZMax = myData->myROctBoolVoxels->GetZ() + myData->myROctBoolVoxels->GetZLen();
+    }
+    if (!myData->myTriangulation.IsNull())
+    {
+        Standard_Real x, y, z;
+        const TColgp_Array1OfPnt& nodes = myData->myTriangulation->Nodes();
+        Standard_Integer inode = nodes.Lower(), nb_nodes = nodes.Upper();
+        for (; inode <= nb_nodes; inode++)
+        {
+            nodes.Value(inode).Coord(x, y, z);
+            if (theMinMax.XMin > x)
+                   theMinMax.XMin = x;
+            if (theMinMax.XMax < x)
+                   theMinMax.XMax = x;
+            if (theMinMax.YMin > y)
+                   theMinMax.YMin = y;
+            if (theMinMax.YMax < y)
+                   theMinMax.YMax = y;
+            if (theMinMax.ZMin > z)
+                   theMinMax.ZMin = z;
+            if (theMinMax.ZMax < z)
+                   theMinMax.ZMax = z;
+        }
+    }
+}
+
+/**************************************************************************/
+void VoxelClient_VisDrawer::Display(const Standard_Boolean theHighlight)
+{
+    if (!myData)
+        return;
+    if (myData->myBoolVoxels)
+        DisplayVoxels(theHighlight);
+    if (myData->myColorVoxels)
+        DisplayVoxels(theHighlight);
+    if (myData->myROctBoolVoxels)
+        DisplayVoxels(theHighlight);
+    if (!myData->myTriangulation.IsNull())
+        DisplayTriangulation(theHighlight);
+}
+
+// Some static method to define Open GL visual attributes
+// COlor
+static void setColor(const Quantity_Color& color, const Standard_Boolean highlight)
+{
+    static Quantity_Color highlight_color(Quantity_NOC_BLUE1);
+               if(highlight)
+        glColor3f(highlight_color.Red(), highlight_color.Green(), highlight_color.Blue());
+    else
+        glColor3d(color.Red(), color.Green(), color.Blue());
+}
+
+// Type of Line
+static void setTypeOfLine(const Aspect_TypeOfLine type)
+{
+    if(type == Aspect_TOL_SOLID)
+    {
+        glDisable(GL_LINE_STIPPLE);
+    }
+    else
+    {
+        glEnable(GL_LINE_STIPPLE);
+        if(type == Aspect_TOL_DOT)
+            glLineStipple(1, 0xCCCC);
+        else if(type == Aspect_TOL_DASH)
+            glLineStipple(1, 0xFFC0);
+        else if(type == Aspect_TOL_DOTDASH)
+            glLineStipple(1, 0xFF18);
+    }
+}
+
+// Width of Line
+static void setWidthOfLine(const Standard_Integer width)
+{
+    glLineWidth((Standard_ShortReal) width);
+}
+
+// Normal of the view
+static void getNormal(gp_Dir& normal) 
+{
+       Standard_Real x, y, z;
+       GLint viewport[4];
+       GLdouble model_matrix[16], proj_matrix[16];
+
+       glGetDoublev(GL_MODELVIEW_MATRIX,  model_matrix);
+       glGetDoublev(GL_PROJECTION_MATRIX, proj_matrix);
+       glGetIntegerv(GL_VIEWPORT, viewport);
+
+       gluUnProject(viewport[0], viewport[1], 0., model_matrix, proj_matrix, viewport, &x, &y, &z);
+       gp_Pnt p1(x, y, z);
+       gluUnProject(viewport[0] + viewport[2], viewport[1], 0., model_matrix, proj_matrix, viewport, &x, &y, &z);
+       gp_Pnt p2(x, y, z);
+       gluUnProject(viewport[0], viewport[1] + viewport[3], 0., model_matrix, proj_matrix, viewport, &x, &y, &z);
+       gp_Pnt p3(x, y, z);
+
+       gce_MakePln mkNormal(p1, p2, p3);
+       if (mkNormal.IsDone()) 
+       {
+               const gp_Pln& normal_plane = mkNormal.Value();
+               normal = normal_plane.Axis().Direction();
+       }
+       else
+       {
+               normal = gp::DZ();
+       }
+}
+
+// Normal 2 VoxelDirection converter
+static VoxelDirection getVoxelDirection(const gp_Dir& viewnormal)
+{
+    VoxelDirection vdir;
+       Standard_Real fabsviewnormalx = fabs(viewnormal.X());
+       Standard_Real fabsviewnormaly = fabs(viewnormal.Y());
+       Standard_Real fabsviewnormalz = fabs(viewnormal.Z());
+       if (fabsviewnormalx >= fabsviewnormaly &&
+               fabsviewnormalx >= fabsviewnormalz)
+       {
+               if (viewnormal.X() > 0)
+                       vdir = Xminus;
+               else
+                       vdir = Xplus;
+       }
+       else if (fabsviewnormaly >= fabsviewnormalx &&
+                        fabsviewnormaly >= fabsviewnormalz)
+       {
+               if (viewnormal.Y() > 0)
+                       vdir = Yminus;
+               else
+                       vdir = Yplus;
+       }
+       else if (fabsviewnormalz >= fabsviewnormalx &&
+                        fabsviewnormalz >= fabsviewnormaly)
+       {
+               if (viewnormal.Z() > 0)
+                       vdir = Zminus;
+               else
+                       vdir = Zplus;
+       }
+    return vdir;
+}
+
+// Normal 2 VoxelDirection 3 converter
+static void getVoxel3Directions(const gp_Dir& viewnormal,
+                                VoxelDirection& vdir1,
+                                VoxelDirection& vdir2,
+                                VoxelDirection& vdir3)
+{
+    Standard_Boolean vdir1_set = Standard_False, vdir2_set = Standard_False, vdir3_set = Standard_False;
+
+    // Test X minus
+    Standard_Real dot = viewnormal.Dot(-gp::DX());
+    if (dot >= 0.0)
+    {
+        if (!vdir1_set)
+        {
+            vdir1 = Xminus;
+            vdir1_set = Standard_True;
+        }
+        else if (!vdir2_set)
+        {
+            vdir2 = Xminus;
+            vdir2_set = Standard_True;
+        }
+        else if (!vdir3_set)
+        {
+            vdir3 = Xminus;
+            vdir3_set = Standard_True;
+        }
+    }
+
+    // Test X plus
+    dot = viewnormal.Dot(gp::DX());
+    if (dot >= 0.0)
+    {
+        if (!vdir1_set)
+        {
+            vdir1 = Xplus;
+            vdir1_set = Standard_True;
+        }
+        else if (!vdir2_set)
+        {
+            vdir2 = Xplus;
+            vdir2_set = Standard_True;
+        }
+        else if (!vdir3_set)
+        {
+            vdir3 = Xplus;
+            vdir3_set = Standard_True;
+        }
+    }
+
+    // Test Y minus
+    dot = viewnormal.Dot(-gp::DY());
+    if (dot >= 0.0)
+    {
+        if (!vdir1_set)
+        {
+            vdir1 = Yminus;
+            vdir1_set = Standard_True;
+        }
+        else if (!vdir2_set)
+        {
+            vdir2 = Yminus;
+            vdir2_set = Standard_True;
+        }
+        else if (!vdir3_set)
+        {
+            vdir3 = Yminus;
+            vdir3_set = Standard_True;
+        }
+    }
+
+    // Test Y plus
+    dot = viewnormal.Dot(gp::DY());
+    if (dot >= 0.0)
+    {
+        if (!vdir1_set)
+        {
+            vdir1 = Yplus;
+            vdir1_set = Standard_True;
+        }
+        else if (!vdir2_set)
+        {
+            vdir2 = Yplus;
+            vdir2_set = Standard_True;
+        }
+        else if (!vdir3_set)
+        {
+            vdir3 = Yplus;
+            vdir3_set = Standard_True;
+        }
+    }
+
+    // Test Z minus
+    dot = viewnormal.Dot(-gp::DZ());
+    if (dot >= 0.0)
+    {
+        if (!vdir1_set)
+        {
+            vdir1 = Zminus;
+            vdir1_set = Standard_True;
+        }
+        else if (!vdir2_set)
+        {
+            vdir2 = Zminus;
+            vdir2_set = Standard_True;
+        }
+        else if (!vdir3_set)
+        {
+            vdir3 = Zminus;
+            vdir3_set = Standard_True;
+        }
+    }
+
+    // Test Y plus
+    dot = viewnormal.Dot(gp::DZ());
+    if (dot >= 0.0)
+    {
+        if (!vdir1_set)
+        {
+            vdir1 = Zplus;
+            vdir1_set = Standard_True;
+        }
+        else if (!vdir2_set)
+        {
+            vdir2 = Zplus;
+            vdir2_set = Standard_True;
+        }
+        else if (!vdir3_set)
+        {
+            vdir3 = Zplus;
+            vdir3_set = Standard_True;
+        }
+    }
+}
+
+static Standard_Boolean CheckSize(Voxel_DS* voxels, 
+                      const Standard_Integer ix, const Standard_Integer iy, const Standard_Integer iz, 
+                      const Standard_Real xmin, const Standard_Real xmax,
+                      const Standard_Real ymin, const Standard_Real ymax,
+                      const Standard_Real zmin, const Standard_Real zmax,
+                      Standard_Real& xc, Standard_Real& yc, Standard_Real& zc)
+{
+    voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+    if (xc < xmin || xc > xmax)
+        return Standard_False;
+    if (yc < ymin || yc > ymax)
+        return Standard_False;
+    if (zc < zmin || zc > zmax)
+        return Standard_False;
+    return Standard_True;
+}
+
+static Standard_Boolean CheckSize(Voxel_ROctBoolDS* voxels, 
+                      const Standard_Integer ix, const Standard_Integer iy, const Standard_Integer iz, 
+                      const Standard_Integer i, const Standard_Integer j,
+                      const Standard_Real xmin, const Standard_Real xmax,
+                      const Standard_Real ymin, const Standard_Real ymax,
+                      const Standard_Real zmin, const Standard_Real zmax,
+                      Standard_Real& xc, Standard_Real& yc, Standard_Real& zc)
+{
+    if (j == -1)
+        voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+    else
+        voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+    if (xc < xmin || xc > xmax)
+        return Standard_False;
+    if (yc < ymin || yc > ymax)
+        return Standard_False;
+    if (zc < zmin || zc > zmax)
+        return Standard_False;
+    return Standard_True;
+}
+
+static void drawBoolPoints(const VoxelDirection vdir, const Standard_Boolean nearest,
+                           Voxel_BoolDS* voxels,
+                           const Standard_Real xmin, const Standard_Real xmax,
+                           const Standard_Real ymin, const Standard_Real ymax,
+                           const Standard_Real zmin, const Standard_Real zmax)
+{
+       Standard_Real xc, yc, zc;
+       Standard_Integer ix = 0, nbx = voxels->GetNbX();
+       Standard_Integer iy = 0, nby = voxels->GetNbY();
+       Standard_Integer iz = 0, nbz = voxels->GetNbZ();
+
+    Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
+                       ymin <= DBL_MAX && ymax >= DBL_MAX &&
+                       zmin <= DBL_MAX && zmax >= DBL_MAX);
+    check_size = !check_size;
+
+    glBegin(GL_POINTS);
+    switch (vdir)
+       {
+               case Xminus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = 0; ix < nbx; ix++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                                               Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                               if (value)
+                                               {
+                            if (!check_size)
+                                                           voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                       glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                                               }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Xplus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = nbx - 1; ix >= 0; ix--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                                               Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                               if (value)
+                                               {
+                            if (!check_size)
+                                                       voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                       glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                                               }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = 0; iy < nby; iy++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                                               Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                               if (value)
+                                               {
+                            if (!check_size)
+                                                       voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                       glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                                               }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = nby - 1; iy >= 0; iy--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                                               Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                               if (value)
+                                               {
+                            if (!check_size)
+                                                       voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                       glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                                               }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = 0; iz < nbz; iz++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                                               Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                               if (value)
+                                               {
+                            if (!check_size)
+                                                       voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                       glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                                               }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = nbz - 1; iz >= 0; iz--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                                               Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                               if (value)
+                                               {
+                            if (!check_size)
+                                                       voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                       glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                                               }
+                                       }
+                               }
+                       }
+                       break;
+               }
+       }
+    glEnd();
+}
+
+static void drawROctBoolPoints(const VoxelDirection vdir, const Standard_Boolean nearest,
+                               Voxel_ROctBoolDS* voxels,
+                               const Standard_Real xmin, const Standard_Real xmax,
+                               const Standard_Real ymin, const Standard_Real ymax,
+                               const Standard_Real zmin, const Standard_Real zmax)
+{
+       Standard_Real xc, yc, zc;
+       Standard_Integer ix = 0, nbx = voxels->GetNbX();
+       Standard_Integer iy = 0, nby = voxels->GetNbY();
+       Standard_Integer iz = 0, nbz = voxels->GetNbZ();
+    Standard_Integer i, j;
+
+    Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
+                       ymin <= DBL_MAX && ymax >= DBL_MAX &&
+                       zmin <= DBL_MAX && zmax >= DBL_MAX);
+    check_size = !check_size;
+
+    glBegin(GL_POINTS);
+    switch (vdir)
+       {
+               case Xminus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = 0; ix < nbx; ix++)
+                                       {
+                        switch (voxels->Deepness(ix, iy, iz))
+                        {
+                            case 0:
+                            {
+                                if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                    continue;
+                                                       Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                                       if (value)
+                                                       {
+                                    if (!check_size)
+                                                                   ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                               glVertex3d(xc, yc, zc);
+                                    if (nearest)
+                                        break;
+                                                       }
+                                break;
+                            }
+                            case 1:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                                           Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                                           if (value)
+                                                           {
+                                        if (!check_size)
+                                                                       voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                                   glVertex3d(xc, yc, zc);
+                                        if (nearest)
+                                            break;
+                                                           }
+                                }
+                                break;
+                            }
+                            case 2:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    for (j = 0; j < 8; j++)
+                                    {
+                                        if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                            continue;
+                                                               Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                                               if (value)
+                                                               {
+                                            if (!check_size)
+                                                                           voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                                       glVertex3d(xc, yc, zc);
+                                            if (nearest)
+                                                break;
+                                                               }
+                                    }
+                                }
+                                break;
+                            }
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Xplus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = nbx - 1; ix >= 0; ix--)
+                                       {
+                        switch (voxels->Deepness(ix, iy, iz))
+                        {
+                            case 0:
+                            {
+                                if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                    continue;
+                                                       Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                                       if (value)
+                                                       {
+                                    if (!check_size)
+                                                                   ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                               glVertex3d(xc, yc, zc);
+                                    if (nearest)
+                                        break;
+                                                       }
+                                break;
+                            }
+                            case 1:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                                           Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                                           if (value)
+                                                           {
+                                        if (!check_size)
+                                                                       voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                                   glVertex3d(xc, yc, zc);
+                                        if (nearest)
+                                            break;
+                                                           }
+                                }
+                                break;
+                            }
+                            case 2:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    for (j = 0; j < 8; j++)
+                                    {
+                                        if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                            continue;
+                                                               Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                                               if (value)
+                                                               {
+                                            if (!check_size)
+                                                                           voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                                       glVertex3d(xc, yc, zc);
+                                            if (nearest)
+                                                break;
+                                                               }
+                                    }
+                                }
+                                break;
+                            }
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = 0; iy < nby; iy++)
+                                       {
+                        switch (voxels->Deepness(ix, iy, iz))
+                        {
+                            case 0:
+                            {
+                                if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                    continue;
+                                                       Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                                       if (value)
+                                                       {
+                                    if (!check_size)
+                                                                   ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                               glVertex3d(xc, yc, zc);
+                                    if (nearest)
+                                        break;
+                                                       }
+                                break;
+                            }
+                            case 1:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                                           Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                                           if (value)
+                                                           {
+                                        if (!check_size)
+                                                                       voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                                   glVertex3d(xc, yc, zc);
+                                        if (nearest)
+                                            break;
+                                                           }
+                                }
+                                break;
+                            }
+                            case 2:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    for (j = 0; j < 8; j++)
+                                    {
+                                        if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                            continue;
+                                                               Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                                               if (value)
+                                                               {
+                                            if (!check_size)
+                                                                           voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                                       glVertex3d(xc, yc, zc);
+                                            if (nearest)
+                                                break;
+                                                               }
+                                    }
+                                }
+                                break;
+                            }
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = nby - 1; iy >= 0; iy--)
+                                       {
+                        switch (voxels->Deepness(ix, iy, iz))
+                        {
+                            case 0:
+                            {
+                                if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                    continue;
+                                                       Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                                       if (value)
+                                                       {
+                                    if (!check_size)
+                                                                   ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                               glVertex3d(xc, yc, zc);
+                                    if (nearest)
+                                        break;
+                                                       }
+                                break;
+                            }
+                            case 1:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                                           Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                                           if (value)
+                                                           {
+                                        if (!check_size)
+                                                                       voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                                   glVertex3d(xc, yc, zc);
+                                        if (nearest)
+                                            break;
+                                                           }
+                                }
+                                break;
+                            }
+                            case 2:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    for (j = 0; j < 8; j++)
+                                    {
+                                        if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                            continue;
+                                                               Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                                               if (value)
+                                                               {
+                                            if (!check_size)
+                                                                           voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                                       glVertex3d(xc, yc, zc);
+                                            if (nearest)
+                                                break;
+                                                               }
+                                    }
+                                }
+                                break;
+                            }
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = 0; iz < nbz; iz++)
+                                       {
+                        switch (voxels->Deepness(ix, iy, iz))
+                        {
+                            case 0:
+                            {
+                                if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                    continue;
+                                                       Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                                       if (value)
+                                                       {
+                                    if (!check_size)
+                                                                   ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                               glVertex3d(xc, yc, zc);
+                                    if (nearest)
+                                        break;
+                                                       }
+                                break;
+                            }
+                            case 1:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                                           Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                                           if (value)
+                                                           {
+                                        if (!check_size)
+                                                                       voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                                   glVertex3d(xc, yc, zc);
+                                        if (nearest)
+                                            break;
+                                                           }
+                                }
+                                break;
+                            }
+                            case 2:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    for (j = 0; j < 8; j++)
+                                    {
+                                        if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                            continue;
+                                                               Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                                               if (value)
+                                                               {
+                                            if (!check_size)
+                                                                           voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                                       glVertex3d(xc, yc, zc);
+                                            if (nearest)
+                                                break;
+                                                               }
+                                    }
+                                }
+                                break;
+                            }
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = nbz - 1; iz >= 0; iz--)
+                                       {
+                        switch (voxels->Deepness(ix, iy, iz))
+                        {
+                            case 0:
+                            {
+                                if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                    continue;
+                                                       Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                                                       if (value)
+                                                       {
+                                    if (!check_size)
+                                                                   ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                               glVertex3d(xc, yc, zc);
+                                    if (nearest)
+                                        break;
+                                                       }
+                                break;
+                            }
+                            case 1:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                                           Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                                           if (value)
+                                                           {
+                                        if (!check_size)
+                                                                       voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                                   glVertex3d(xc, yc, zc);
+                                        if (nearest)
+                                            break;
+                                                           }
+                                }
+                                break;
+                            }
+                            case 2:
+                            {
+                                for (i = 0; i < 8; i++)
+                                {
+                                    for (j = 0; j < 8; j++)
+                                    {
+                                        if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                            continue;
+                                                               Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                                               if (value)
+                                                               {
+                                            if (!check_size)
+                                                                           voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                                       glVertex3d(xc, yc, zc);
+                                            if (nearest)
+                                                break;
+                                                               }
+                                    }
+                                }
+                                break;
+                            }
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+       }
+    glEnd();
+}
+
+
+
+static void drawColorPoints(const VoxelDirection vdir, const Standard_Boolean nearest,
+                            Voxel_ColorDS* voxels, const Handle(Quantity_HArray1OfColor)& hcolors,
+                            const Standard_Byte minvalue, const Standard_Byte maxvalue,
+                            const Standard_Real xmin, const Standard_Real xmax,
+                            const Standard_Real ymin, const Standard_Real ymax,
+                            const Standard_Real zmin, const Standard_Real zmax)
+{
+       Standard_Real xc, yc, zc;
+       Standard_Integer ix = 0, nbx = voxels->GetNbX();
+       Standard_Integer iy = 0, nby = voxels->GetNbY();
+       Standard_Integer iz = 0, nbz = voxels->GetNbZ();
+    Standard_Byte value;
+
+    // Colors
+    const Quantity_Array1OfColor& colors = hcolors->Array1();
+
+    Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
+                       ymin <= DBL_MAX && ymax >= DBL_MAX &&
+                       zmin <= DBL_MAX && zmax >= DBL_MAX);
+    check_size = !check_size;
+
+    glBegin(GL_POINTS);
+    switch (vdir)
+       {
+               case Xminus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = 0; ix < nbx; ix++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                           value = voxels->Get(ix, iy, iz);
+                           if (value >= minvalue && value <= maxvalue)
+                           {
+                            if (!check_size)
+                                       voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            setColor(colors.Value(value), Standard_False);
+                                   glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Xplus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = nbx - 1; ix >= 0; ix--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                           value = voxels->Get(ix, iy, iz);
+                           if (value >= minvalue && value <= maxvalue)
+                           {
+                            if (!check_size)
+                                       voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            setColor(colors.Value(value), Standard_False);
+                                   glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = 0; iy < nby; iy++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                           value = voxels->Get(ix, iy, iz);
+                           if (value >= minvalue && value <= maxvalue)
+                           {
+                            if (!check_size)
+                                       voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            setColor(colors.Value(value), Standard_False);
+                                   glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = nby - 1; iy >= 0; iy--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                           value = voxels->Get(ix, iy, iz);
+                           if (value >= minvalue && value <= maxvalue)
+                           {
+                            if (!check_size)
+                                       voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            setColor(colors.Value(value), Standard_False);
+                                   glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = 0; iz < nbz; iz++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                           value = voxels->Get(ix, iy, iz);
+                           if (value >= minvalue && value <= maxvalue)
+                           {
+                            if (!check_size)
+                                       voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            setColor(colors.Value(value), Standard_False);
+                                   glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = nbz - 1; iz >= 0; iz--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                           value = voxels->Get(ix, iy, iz);
+                           if (value >= minvalue && value <= maxvalue)
+                           {
+                            if (!check_size)
+                                       voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            setColor(colors.Value(value), Standard_False);
+                                   glVertex3d(xc, yc, zc);
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+    }
+    glEnd();
+}
+
+static void drawBoolQuadrangles(Voxel_BoolDS* voxels, const VoxelDirection vdir, 
+                                const gp_Dir& viewnormal, const Standard_Boolean nearest,
+                                const gp_Pnt& p1, const gp_Pnt& p2, const gp_Pnt& p3, const gp_Pnt& p4,
+                                const Standard_Real xmin, const Standard_Real xmax,
+                                const Standard_Real ymin, const Standard_Real ymax,
+                                const Standard_Real zmin, const Standard_Real zmax)
+{
+    gp_Vec vc;
+    gp_Pnt pc1, pc2, pc3, pc4;
+    Standard_Real xc, yc, zc, xn = 0.0, yn = 0.0, zn = 1.0;
+    Standard_Integer ix, iy, iz, nbx = voxels->GetNbX(), nby = voxels->GetNbY(), nbz = voxels->GetNbZ();
+
+    // Normal
+    viewnormal.Coord(xn, yn, zn);
+
+    Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
+                       ymin <= DBL_MAX && ymax >= DBL_MAX &&
+                       zmin <= DBL_MAX && zmax >= DBL_MAX);
+    check_size = !check_size;
+
+    glBegin(GL_QUADS);
+    switch (vdir)
+       {
+               case Xminus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = 0; ix < nbx; ix++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                        if (value)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Display
+                            glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                    }
+                               }
+                       }
+                       break;
+               }
+               case Xplus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = nbx - 1; ix >= 0; ix--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                        if (value)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Display
+                            glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = 0; iy < nby; iy++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                        if (value)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Display
+                            glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = nby - 1; iy >= 0; iy--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                        if (value)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Display
+                            glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = 0; iz < nbz; iz++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                        if (value)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Display
+                            glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = nbz - 1; iz >= 0; iz--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
+                        if (value)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Display
+                            glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+    }
+    glEnd();
+}
+
+static void drawROctBoolQuadrangles(Voxel_ROctBoolDS* voxels, const VoxelDirection vdir, 
+                                    const gp_Dir& viewnormal, const Standard_Boolean nearest,
+                                    const gp_Pnt& p1, const gp_Pnt& p2, const gp_Pnt& p3, const gp_Pnt& p4,
+                                    const Standard_Real xmin, const Standard_Real xmax,
+                                    const Standard_Real ymin, const Standard_Real ymax,
+                                    const Standard_Real zmin, const Standard_Real zmax)
+{
+    gp_Vec vc;
+    gp_Pnt pc1, pc2, pc3, pc4;
+    Standard_Real xc, yc, zc, xn = 0.0, yn = 0.0, zn = 1.0;
+    Standard_Integer ix, iy, iz, nbx = voxels->GetNbX(), nby = voxels->GetNbY(), nbz = voxels->GetNbZ(), i, j, deepness;
+
+    // Normal
+    viewnormal.Coord(xn, yn, zn);
+
+    Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
+                       ymin <= DBL_MAX && ymax >= DBL_MAX &&
+                       zmin <= DBL_MAX && zmax >= DBL_MAX);
+    check_size = !check_size;
+
+    glBegin(GL_QUADS);
+    switch (vdir)
+       {
+               case Xminus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = 0; ix < nbx; ix++)
+                                       {
+                        deepness = voxels->Deepness(ix, iy, iz);
+                        for (i = 0; i < 8; i++)
+                        {
+                            for (j = 0; j < 8; j++)
+                            {
+                                if (deepness == 0 && j)
+                                {
+                                    i = 8;
+                                    break;
+                                }
+                                if (deepness == 1 && j)
+                                    break;
+                                if (deepness == 0)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 1)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 2)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+
+                                Standard_Boolean value;
+                                switch (deepness)
+                                {
+                                    case 0:
+                                        value = voxels->Get(ix, iy, iz) == Standard_True;
+                                        break;
+                                    case 1:
+                                        value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                        break;
+                                    case 2:
+                                        value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                        break;
+                                }
+                                
+                                if (value)
+                                {
+                                    // Define translation vector
+                                    if (!check_size)
+                                    {
+                                        switch (deepness)
+                                        {
+                                            case 0:
+                                                ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                break;
+                                            case 1:
+                                                voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                break;
+                                            case 2:
+                                                voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                break;
+                                        }
+                                    }
+                                    vc.SetCoord(xc, yc, zc);
+
+                                    // Translate
+                                    pc1 = p1.Translated(vc);
+                                    pc2 = p2.Translated(vc);
+                                    pc3 = p3.Translated(vc);
+                                    pc4 = p4.Translated(vc);
+
+                                    // Display
+                                    glNormal3d(xn, yn, zn);
+                                    pc1.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc2.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc3.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc4.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+
+                                    if (nearest)
+                                        break;
+                                }
+                            }
+                        }
+                    }
+                               }
+                       }
+                       break;
+               }
+               case Xplus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = nbx - 1; ix >= 0; ix--)
+                                       {
+                        deepness = voxels->Deepness(ix, iy, iz);
+                        for (i = 0; i < 8; i++)
+                        {
+                            for (j = 0; j < 8; j++)
+                            {
+                                if (deepness == 0 && j)
+                                {
+                                    i = 8;
+                                    break;
+                                }
+                                if (deepness == 1 && j)
+                                    break;
+                                if (deepness == 0)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 1)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 2)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+
+                                Standard_Boolean value;
+                                switch (deepness)
+                                {
+                                    case 0:
+                                        value = voxels->Get(ix, iy, iz) == Standard_True;
+                                        break;
+                                    case 1:
+                                        value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                        break;
+                                    case 2:
+                                        value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                        break;
+                                }
+                                
+                                if (value)
+                                {
+                                    // Define translation vector
+                                    if (!check_size)
+                                    {
+                                        switch (deepness)
+                                        {
+                                            case 0:
+                                                ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                break;
+                                            case 1:
+                                                voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                break;
+                                            case 2:
+                                                voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                break;
+                                        }
+                                    }
+                                    vc.SetCoord(xc, yc, zc);
+
+                                    // Translate
+                                    pc1 = p1.Translated(vc);
+                                    pc2 = p2.Translated(vc);
+                                    pc3 = p3.Translated(vc);
+                                    pc4 = p4.Translated(vc);
+
+                                    // Display
+                                    glNormal3d(xn, yn, zn);
+                                    pc1.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc2.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc3.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc4.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+
+                                    if (nearest)
+                                        break;
+                                }
+                            }
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = 0; iy < nby; iy++)
+                                       {
+                        deepness = voxels->Deepness(ix, iy, iz);
+                        for (i = 0; i < 8; i++)
+                        {
+                            for (j = 0; j < 8; j++)
+                            {
+                                if (deepness == 0 && j)
+                                {
+                                    i = 8;
+                                    break;
+                                }
+                                if (deepness == 1 && j)
+                                    break;
+                                if (deepness == 0)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 1)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 2)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+
+                                Standard_Boolean value;
+                                switch (deepness)
+                                {
+                                    case 0:
+                                        value = voxels->Get(ix, iy, iz) == Standard_True;
+                                        break;
+                                    case 1:
+                                        value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                        break;
+                                    case 2:
+                                        value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                        break;
+                                }
+                                
+                                if (value)
+                                {
+                                    // Define translation vector
+                                    if (!check_size)
+                                    {
+                                        switch (deepness)
+                                        {
+                                            case 0:
+                                                ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                break;
+                                            case 1:
+                                                voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                break;
+                                            case 2:
+                                                voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                break;
+                                        }
+                                    }
+                                    vc.SetCoord(xc, yc, zc);
+
+                                    // Translate
+                                    pc1 = p1.Translated(vc);
+                                    pc2 = p2.Translated(vc);
+                                    pc3 = p3.Translated(vc);
+                                    pc4 = p4.Translated(vc);
+
+                                    // Display
+                                    glNormal3d(xn, yn, zn);
+                                    pc1.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc2.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc3.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc4.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+
+                                    if (nearest)
+                                        break;
+                                }
+                            }
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = nby - 1; iy >= 0; iy--)
+                                       {
+                        deepness = voxels->Deepness(ix, iy, iz);
+                        for (i = 0; i < 8; i++)
+                        {
+                            for (j = 0; j < 8; j++)
+                            {
+                                if (deepness == 0 && j)
+                                {
+                                    i = 8;
+                                    break;
+                                }
+                                if (deepness == 1 && j)
+                                    break;
+                                if (deepness == 0)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 1)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 2)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+
+                                Standard_Boolean value;
+                                switch (deepness)
+                                {
+                                    case 0:
+                                        value = voxels->Get(ix, iy, iz) == Standard_True;
+                                        break;
+                                    case 1:
+                                        value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                        break;
+                                    case 2:
+                                        value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                        break;
+                                }
+                                
+                                if (value)
+                                {
+                                    // Define translation vector
+                                    if (!check_size)
+                                    {
+                                        switch (deepness)
+                                        {
+                                            case 0:
+                                                ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                break;
+                                            case 1:
+                                                voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                break;
+                                            case 2:
+                                                voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                break;
+                                        }
+                                    }
+                                    vc.SetCoord(xc, yc, zc);
+
+                                    // Translate
+                                    pc1 = p1.Translated(vc);
+                                    pc2 = p2.Translated(vc);
+                                    pc3 = p3.Translated(vc);
+                                    pc4 = p4.Translated(vc);
+
+                                    // Display
+                                    glNormal3d(xn, yn, zn);
+                                    pc1.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc2.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc3.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc4.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+
+                                    if (nearest)
+                                        break;
+                                }
+                            }
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = 0; iz < nbz; iz++)
+                                       {
+                        deepness = voxels->Deepness(ix, iy, iz);
+                        for (i = 0; i < 8; i++)
+                        {
+                            for (j = 0; j < 8; j++)
+                            {
+                                if (deepness == 0 && j)
+                                {
+                                    i = 8;
+                                    break;
+                                }
+                                if (deepness == 1 && j)
+                                    break;
+                                if (deepness == 0)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 1)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 2)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+
+                                Standard_Boolean value;
+                                switch (deepness)
+                                {
+                                    case 0:
+                                        value = voxels->Get(ix, iy, iz) == Standard_True;
+                                        break;
+                                    case 1:
+                                        value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                        break;
+                                    case 2:
+                                        value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                        break;
+                                }
+                                
+                                if (value)
+                                {
+                                    // Define translation vector
+                                    if (!check_size)
+                                    {
+                                        switch (deepness)
+                                        {
+                                            case 0:
+                                                ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                break;
+                                            case 1:
+                                                voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                break;
+                                            case 2:
+                                                voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                break;
+                                        }
+                                    }
+                                    vc.SetCoord(xc, yc, zc);
+
+                                    // Translate
+                                    pc1 = p1.Translated(vc);
+                                    pc2 = p2.Translated(vc);
+                                    pc3 = p3.Translated(vc);
+                                    pc4 = p4.Translated(vc);
+
+                                    // Display
+                                    glNormal3d(xn, yn, zn);
+                                    pc1.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc2.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc3.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc4.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+
+                                    if (nearest)
+                                        break;
+                                }
+                            }
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = nbz - 1; iz >= 0; iz--)
+                                       {
+                        deepness = voxels->Deepness(ix, iy, iz);
+                        for (i = 0; i < 8; i++)
+                        {
+                            for (j = 0; j < 8; j++)
+                            {
+                                if (deepness == 0 && j)
+                                {
+                                    i = 8;
+                                    break;
+                                }
+                                if (deepness == 1 && j)
+                                    break;
+                                if (deepness == 0)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 1)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+                                else if (deepness == 2)
+                                {
+                                    if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                                        continue;
+                                }
+
+                                Standard_Boolean value;
+                                switch (deepness)
+                                {
+                                    case 0:
+                                        value = voxels->Get(ix, iy, iz) == Standard_True;
+                                        break;
+                                    case 1:
+                                        value = voxels->Get(ix, iy, iz, i) == Standard_True;
+                                        break;
+                                    case 2:
+                                        value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
+                                        break;
+                                }
+                                
+                                if (value)
+                                {
+                                    // Define translation vector
+                                    if (!check_size)
+                                    {
+                                        switch (deepness)
+                                        {
+                                            case 0:
+                                                ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
+                                                break;
+                                            case 1:
+                                                voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
+                                                break;
+                                            case 2:
+                                                voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
+                                                break;
+                                        }
+                                    }
+                                    vc.SetCoord(xc, yc, zc);
+
+                                    // Translate
+                                    pc1 = p1.Translated(vc);
+                                    pc2 = p2.Translated(vc);
+                                    pc3 = p3.Translated(vc);
+                                    pc4 = p4.Translated(vc);
+
+                                    // Display
+                                    glNormal3d(xn, yn, zn);
+                                    pc1.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc2.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc3.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+                                    pc4.Coord(xc, yc, zc);
+                                    glVertex3d(xc, yc, zc);
+
+                                    if (nearest)
+                                        break;
+                                }
+                            }
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+    }
+    glEnd();
+}
+
+
+
+static void drawColorQuadrangles(Voxel_ColorDS* voxels, const VoxelDirection vdir, 
+                                 const gp_Dir& viewnormal, const Standard_Boolean nearest,
+                                 const Handle(Quantity_HArray1OfColor)& hcolors,
+                                 const gp_Pnt& p1, const gp_Pnt& p2, const gp_Pnt& p3, const gp_Pnt& p4,
+                                 const Standard_Byte minvalue, const Standard_Byte maxvalue,
+                                 const Standard_Real xmin, const Standard_Real xmax,
+                                 const Standard_Real ymin, const Standard_Real ymax,
+                                 const Standard_Real zmin, const Standard_Real zmax)
+{
+    gp_Vec vc;
+    gp_Pnt pc1, pc2, pc3, pc4;
+    Standard_Real xc, yc, zc, xn = 0.0, yn = 0.0, zn = 0.0;
+    Standard_Integer ix, iy, iz, nbx = voxels->GetNbX(), nby = voxels->GetNbY(), nbz = voxels->GetNbZ();
+    Standard_Byte value;
+
+    // Normal
+    //viewnormal.Coord(xn, yn, zn);
+    glNormal3d(xn, yn, zn);
+
+    // Colors
+    const Quantity_Array1OfColor& colors = hcolors->Array1();
+
+    Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
+                       ymin <= DBL_MAX && ymax >= DBL_MAX &&
+                       zmin <= DBL_MAX && zmax >= DBL_MAX);
+    check_size = !check_size;
+
+    glBegin(GL_QUADS);
+    switch (vdir)
+       {
+               case Xminus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = 0; ix < nbx; ix++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        value = voxels->Get(ix, iy, iz);
+                        if (value >= minvalue && value <= maxvalue)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Color
+                            setColor(colors.Value(value), Standard_False);
+
+                            // Display
+                            //glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                    }
+                               }
+                       }
+                       break;
+               }
+               case Xplus:
+               {
+                       for (iy = 0; iy < nby; iy++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (ix = nbx - 1; ix >= 0; ix--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        value = voxels->Get(ix, iy, iz);
+                        if (value >= minvalue && value <= maxvalue)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Color
+                            setColor(colors.Value(value), Standard_False);
+
+                            // Display
+                            //glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = 0; iy < nby; iy++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        value = voxels->Get(ix, iy, iz);
+                        if (value >= minvalue && value <= maxvalue)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Color
+                            setColor(colors.Value(value), Standard_False);
+
+                            // Display
+                            //glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Yplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iz = 0; iz < nbz; iz++)
+                               {
+                                       for (iy = nby - 1; iy >= 0; iy--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        value = voxels->Get(ix, iy, iz);
+                        if (value >= minvalue && value <= maxvalue)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Color
+                            setColor(colors.Value(value), Standard_False);
+
+                            // Display
+                            //glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zminus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = 0; iz < nbz; iz++)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        value = voxels->Get(ix, iy, iz);
+                        if (value >= minvalue && value <= maxvalue)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Color
+                            setColor(colors.Value(value), Standard_False);
+
+                            // Display
+                            //glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               case Zplus:
+               {
+                       for (ix = 0; ix < nbx; ix++)
+                       {
+                               for (iy = 0; iy < nby; iy++)
+                               {
+                                       for (iz = nbz - 1; iz >= 0; iz--)
+                                       {
+                        if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
+                            continue;
+                        value = voxels->Get(ix, iy, iz);
+                        if (value >= minvalue && value <= maxvalue)
+                        {
+                            // Define translation vector
+                            if (!check_size)
+                                voxels->GetCenter(ix, iy, iz, xc, yc, zc);
+                            vc.SetCoord(xc, yc, zc);
+
+                            // Translate
+                            pc1 = p1.Translated(vc);
+                            pc2 = p2.Translated(vc);
+                            pc3 = p3.Translated(vc);
+                            pc4 = p4.Translated(vc);
+
+                            // Color
+                            setColor(colors.Value(value), Standard_False);
+
+                            // Display
+                            //glNormal3d(xn, yn, zn);
+                            pc1.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc2.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc3.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+                            pc4.Coord(xc, yc, zc);
+                            glVertex3d(xc, yc, zc);
+
+                            if (nearest)
+                                break;
+                        }
+                                       }
+                               }
+                       }
+                       break;
+               }
+    }
+    glEnd();
+}
+
+static void genListIndex(GLint& index)
+{
+    GLint i = 0;
+    while (++i <= INT_MAX)
+    {
+        if (!glIsList(i))
+        {
+            index = i;
+            break;
+        }
+    }
+}
+
+static void setPlaneNormal(const VoxelDirection& dir, 
+                           const Standard_Real dx, const Standard_Real dy, const Standard_Real dz,
+                           gp_Pln& plane, gp_Pnt& p1, gp_Pnt& p2, gp_Pnt& p3, gp_Pnt& p4)
+{
+    gp_Ax3 axes = plane.Position();
+    Standard_Real dx2 = 0.5 * dx, dy2 = 0.5 * dy, dz2 = 0.5 * dz;
+    switch (dir)
+    {
+        case Xminus:
+            p1.SetCoord(-dx2, -dy2, dz2);
+            p2.SetCoord(-dx2, -dy2, -dz2);
+            p3.SetCoord(-dx2, dy2, -dz2);
+            p4.SetCoord(-dx2, dy2, dz2);
+            axes.SetDirection(-gp::DX());
+            break;
+        case Xplus:
+            p1.SetCoord(dx2, -dy2, dz2);
+            p2.SetCoord(dx2, -dy2, -dz2);
+            p3.SetCoord(dx2, dy2, -dz2);
+            p4.SetCoord(dx2, dy2, dz2);
+            axes.SetDirection(gp::DX());
+            break;
+        case Yminus:
+            p1.SetCoord(dx2, -dy2, dz2);
+            p2.SetCoord(dx2, -dy2, -dz2);
+            p3.SetCoord(-dx2, -dy2, -dz2);
+            p4.SetCoord(-dx2, -dy2, dz2);
+            axes.SetDirection(-gp::DY());
+            break;
+        case Yplus:
+            p1.SetCoord(dx2, dy2, dz2);
+            p2.SetCoord(dx2, dy2, -dz2);
+            p3.SetCoord(-dx2, dy2, -dz2);
+            p4.SetCoord(-dx2, dy2, dz2);
+            axes.SetDirection(gp::DY());
+            break;
+        case Zminus:
+            p1.SetCoord(dx2, dy2, -dz2);
+            p2.SetCoord(-dx2, dy2, -dz2);
+            p3.SetCoord(-dx2, -dy2, -dz2);
+            p4.SetCoord(dx2, -dy2, -dz2);
+            axes.SetDirection(-gp::DZ());
+            break;
+        case Zplus:
+            p1.SetCoord(dx2, dy2, dz2);
+            p2.SetCoord(-dx2, dy2, dz2);
+            p3.SetCoord(-dx2, -dy2, dz2);
+            p4.SetCoord(dx2, -dy2, dz2);
+            axes.SetDirection(gp::DZ());
+            break;
+    }
+}
+
+/**************************************************************************/
+void VoxelClient_VisDrawer::DisplayVoxels(const Standard_Boolean theHighlight)
+{
+    if(!myData)
+        return;
+
+    glEnable(GL_DEPTH_TEST);
+
+       // Boolean voxels
+       if (myData->myBoolVoxels)
+    {
+               // Points
+               if (myData->myDisplay.myDisplayMode == Voxel_VDM_POINTS ||
+            myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS)
+               {
+                       glDisable(GL_LIGHTING);
+            if (myData->myDisplay.mySmoothPoints)
+                           glEnable(GL_POINT_SMOOTH);
+            else
+                glDisable(GL_POINT_SMOOTH);
+
+                       // Draw the points of voxels (center points of the voxels)
+                       // starting visualization from the side looking out from the user.
+                       setColor(myData->myDisplay.myColor, theHighlight);
+                       glPointSize((Standard_ShortReal) myData->myDisplay.myPointSize);
+
+            // Display
+            DisplayPoints(myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS);
+        }
+       }
+
+    // Color values
+       if (myData->myColorVoxels)
+    {
+               // Points
+               if (myData->myDisplay.myDisplayMode == Voxel_VDM_POINTS ||
+            myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS)
+               {
+                       glDisable(GL_LIGHTING);
+            if (myData->myDisplay.mySmoothPoints)
+                           glEnable(GL_POINT_SMOOTH);
+            else
+                glDisable(GL_POINT_SMOOTH);
+
+                       // Draw the points of voxels (center points of the voxels)
+                       // starting visualization from the side looking out from the user.
+                       glPointSize((Standard_ShortReal) myData->myDisplay.myPointSize);
+
+            // Display
+            DisplayPoints(myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS);
+        }
+       }
+
+       // Recursive Octree Boolean voxels
+       if (myData->myROctBoolVoxels)
+    {
+               // Points
+               if (myData->myDisplay.myDisplayMode == Voxel_VDM_POINTS ||
+            myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS)
+               {
+                       glDisable(GL_LIGHTING);
+            if (myData->myDisplay.mySmoothPoints)
+                           glEnable(GL_POINT_SMOOTH);
+            else
+                glDisable(GL_POINT_SMOOTH);
+
+                       // Draw the points of voxels (center points of the voxels)
+                       // starting visualization from the side looking out from the user.
+                       setColor(myData->myDisplay.myColor, theHighlight);
+                       glPointSize((Standard_ShortReal) myData->myDisplay.myPointSize);
+
+            // Display
+            DisplayPoints(myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS);
+        }
+       }
+
+    // Shading drawn by boxes
+    if (myData->myDisplay.myDisplayMode == Voxel_VDM_BOXES || 
+        myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTBOXES)
+    {
+               glEnable(GL_LIGHTING);
+        glEnable(GL_COLOR_MATERIAL);
+
+               // Draw quadrangles of voxels looking to the user.
+               setColor(myData->myDisplay.myColor, theHighlight);
+
+        // Display
+        DisplayBoxes(myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTBOXES);
+
+        glDisable(GL_COLOR_MATERIAL);
+    }
+
+    // Highlighted voxel
+    HighlightVoxel();
+}
+
+/**************************************************************************/
+void VoxelClient_VisDrawer::DisplayPoints(const Standard_Boolean nearest)
+{
+    //OSD_Timer timer;
+    //timer.Start();
+
+    // Find the side of the cube which normal looks to (or out) the user's eye.
+       gp_Dir viewnormal;
+       getNormal(viewnormal);
+
+    // Range of displayed data
+    Standard_Real xmin = myData->myDisplay.myDisplayedXMin;
+    Standard_Real xmax = myData->myDisplay.myDisplayedXMax;
+    Standard_Real ymin = myData->myDisplay.myDisplayedYMin;
+    Standard_Real ymax = myData->myDisplay.myDisplayedYMax;
+    Standard_Real zmin = myData->myDisplay.myDisplayedZMin;
+    Standard_Real zmax = myData->myDisplay.myDisplayedZMax;
+
+    // Boolean points
+       if (myData->myBoolVoxels)
+    {
+        if (nearest || myData->myDisplay.myDegenerateMode)
+        {
+               VoxelDirection vdir1, vdir2, vdir3;
+            getVoxel3Directions(viewnormal, vdir1, vdir2, vdir3);
+
+            if (myData->myDisplay.myUsageOfGLlists)
+            {
+                // Clean all allocated GL lists for the case of first call.
+                if (myData->myDisplay.myBoolNearestPointsFirst)
+                {
+                    for (Standard_Integer idir = Xminus; idir <= Zplus; idir++)
+                    {
+                        if (myData->myDisplay.myBoolNearestPointsList[idir] > 0)
+                        {
+                            glDeleteLists(myData->myDisplay.myBoolNearestPointsList[idir], 1);
+                            myData->myDisplay.myBoolNearestPointsList[idir] = -1;
+                        }
+                    }
+                    myData->myDisplay.myBoolNearestPointsFirst = Standard_False;
+                }
+
+                // Generate GL lists if needed.
+                if (myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir1] < 0)
+                {
+                    genListIndex(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir1]);
+                    glNewList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir1], GL_COMPILE);
+                    drawBoolPoints(vdir1, Standard_True, myData->myBoolVoxels,
+                                   xmin, xmax, ymin, ymax, zmin, zmax);
+                    glEndList();
+                }
+                if (myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir2] < 0)
+                {
+                    genListIndex(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir2]);
+                    glNewList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir2], GL_COMPILE);
+                    drawBoolPoints(vdir2, Standard_True, myData->myBoolVoxels,
+                                   xmin, xmax, ymin, ymax, zmin, zmax);
+                    glEndList();
+                }
+                if (myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir3] < 0)
+                {
+                    genListIndex(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir3]);
+                    glNewList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir3], GL_COMPILE);
+                    drawBoolPoints(vdir3, Standard_True, myData->myBoolVoxels,
+                                   xmin, xmax, ymin, ymax, zmin, zmax);
+                    glEndList();
+                }
+                glCallList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir1]);
+                glCallList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir2]);
+                glCallList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir3]);
+            }
+            else
+            {
+                drawBoolPoints(vdir1, Standard_True, myData->myBoolVoxels,
+                               xmin, xmax, ymin, ymax, zmin, zmax);
+                drawBoolPoints(vdir2, Standard_True, myData->myBoolVoxels,
+                               xmin, xmax, ymin, ymax, zmin, zmax);
+                drawBoolPoints(vdir3, Standard_True, myData->myBoolVoxels,
+                               xmin, xmax, ymin, ymax, zmin, zmax);
+            }
+        }
+        else
+        {
+            if (myData->myDisplay.myUsageOfGLlists)
+            {
+                if (myData->myDisplay.myBoolPointsFirst)
+                {
+                    // Delete previous GL list.
+                    if (myData->myDisplay.myBoolPointsList > 0)
+                    {
+                        glDeleteLists(myData->myDisplay.myBoolPointsList, 1);
+                        myData->myDisplay.myBoolPointsList = -1;
+                    }
+
+                    // Generate a new GL list
+                    genListIndex(myData->myDisplay.myBoolPointsList);
+                    glNewList(myData->myDisplay.myBoolPointsList, GL_COMPILE);
+                    VoxelDirection vdir = getVoxelDirection(viewnormal);
+                    drawBoolPoints(vdir, Standard_False, myData->myBoolVoxels,
+                                   xmin, xmax, ymin, ymax, zmin, zmax);
+                    glEndList();
+
+                    // The first call has just been passed...
+                    myData->myDisplay.myBoolPointsFirst = Standard_False;
+                }
+                glCallList(myData->myDisplay.myBoolPointsList);
+            }
+            else
+            {
+                VoxelDirection vdir = getVoxelDirection(viewnormal);
+                drawBoolPoints(vdir, Standard_False, myData->myBoolVoxels,
+                               xmin, xmax, ymin, ymax, zmin, zmax);
+            }
+        }
+       }
+
+    // Color points
+       if (myData->myColorVoxels)
+    {
+        if (nearest || myData->myDisplay.myDegenerateMode)
+        {
+               VoxelDirection vdir1, vdir2, vdir3;
+            getVoxel3Directions(viewnormal, vdir1, vdir2, vdir3);
+
+            if (myData->myDisplay.myUsageOfGLlists)
+            {
+                // Clean all allocated GL lists for the case of first call.
+                if (myData->myDisplay.myColorNearestPointsFirst)
+                {
+                    for (Standard_Integer idir = Xminus; idir <= Zplus; idir++)
+                    {
+                        if (myData->myDisplay.myColorNearestPointsList[idir] > 0)
+                      &