]> OCCT Git - occt.git/commitdiff
0024013: Voxel_FastConverter is able to use existing triangulation
authorPawel <pawel-kowalski@wp.pl>
Thu, 13 Jun 2013 10:45:04 +0000 (14:45 +0400)
committerPawel <pawel-kowalski@wp.pl>
Thu, 13 Jun 2013 10:45:04 +0000 (14:45 +0400)
Added the possibility to use existing triangulation within Voxel_FastConverter.
A grammar mistake is corrected.

src/Voxel/Voxel_FastConverter.cdl
src/Voxel/Voxel_FastConverter.cxx

index 10c74d3483dd1f36bafa870304cc2908c7c7716f..14b4f020acc9af524dd1870c75b19f08aaecdc6b 100755 (executable)
@@ -37,11 +37,12 @@ is
 
     Create(shape  :     Shape   from TopoDS;
           voxels : out BoolDS  from Voxel;
-          delfection : Real    from Standard = 0.1;
+          deflection : Real    from Standard = 0.1;
           nbx    :     Integer from Standard = 10;
           nby    :     Integer from Standard = 10;
           nbz    :     Integer from Standard = 10;
-          nbthreads :  Integer from Standard = 1)
+          nbthreads :  Integer from Standard = 1;
+          useExistingTriangulation : Boolean from Standard = Standard_False)
     ---Purpose: A constructor for conversion of a shape into a cube of boolean voxels.
     --          It allocates the voxels in memory.
     --          "nbthreads" defines the number of threads used to convert the shape.
@@ -49,11 +50,12 @@ is
 
     Create(shape  :     Shape   from TopoDS;
           voxels : out ColorDS from Voxel;
-          delfection : Real    from Standard = 0.1;
+          deflection : Real    from Standard = 0.1;
           nbx    :     Integer from Standard = 10;
           nby    :     Integer from Standard = 10;
           nbz    :     Integer from Standard = 10;
-          nbthreads :  Integer from Standard = 1)
+          nbthreads :  Integer from Standard = 1;
+          useExistingTriangulation : Boolean from Standard = Standard_False)
     ---Purpose: A constructor for conversion of a shape into a cube of colored voxels.
     --          It allocates the voxels in memory.
     --          "nbthreads" defines the number of threads used to convert the shape.
@@ -61,11 +63,12 @@ is
 
     Create(shape  :     Shape   from TopoDS;
           voxels : out ROctBoolDS from Voxel;
-          delfection : Real    from Standard = 0.1;
+          deflection : Real    from Standard = 0.1;
           nbx    :     Integer from Standard = 10;
           nby    :     Integer from Standard = 10;
           nbz    :     Integer from Standard = 10;
-          nbthreads :  Integer from Standard = 1)
+          nbthreads :  Integer from Standard = 1;
+          useExistingTriangulation : Boolean from Standard = Standard_False)
     ---Purpose: A constructor for conversion of a shape into a cube of boolean voxels
     --          split into 8 sub-voxels recursively.
     --          It allocates the voxels in memory.
@@ -136,5 +139,6 @@ fields
     myNbZ         : Integer from Standard;
     myNbThreads   : Integer from Standard;
     myNbTriangles : Integer from Standard;
+    myUseExistingTriangulation : Boolean from Standard;
 
 end FastConverter;
index dad9a6ca9337c3711c8789cc860114af9d37da04..2cdc21a47156b5c1837d853eb6c515f333e33cac 100755 (executable)
@@ -45,12 +45,14 @@ Voxel_FastConverter::Voxel_FastConverter(const TopoDS_Shape&    shape,
                                         const Standard_Integer nbx,
                                         const Standard_Integer nby,
                                         const Standard_Integer nbz,
-                                        const Standard_Integer nbthreads)
+                                        const Standard_Integer nbthreads,
+                                        const Standard_Boolean useExistingTriangulation)
 :myShape(shape),myVoxels(&voxels),
  myDeflection(deflection),
  myNbX(nbx),myNbY(nby),myNbZ(nbz),
  myNbThreads(nbthreads),myIsBool(2),
- myNbTriangles(0)
+ myNbTriangles(0),
+ myUseExistingTriangulation(useExistingTriangulation)
 {
   Init();
 }
@@ -61,12 +63,14 @@ Voxel_FastConverter::Voxel_FastConverter(const TopoDS_Shape&    shape,
                                         const Standard_Integer nbx,
                                         const Standard_Integer nby,
                                         const Standard_Integer nbz,
-                                        const Standard_Integer nbthreads)
+                                        const Standard_Integer nbthreads,
+                                        const Standard_Boolean useExistingTriangulation)
 :myShape(shape),myVoxels(&voxels),
  myDeflection(deflection),
  myNbX(nbx),myNbY(nby),myNbZ(nbz),
  myNbThreads(nbthreads),myIsBool(1),
- myNbTriangles(0)
+ myNbTriangles(0),
+ myUseExistingTriangulation(useExistingTriangulation)
 {
   Init();
 }
@@ -77,12 +81,14 @@ Voxel_FastConverter::Voxel_FastConverter(const TopoDS_Shape&    shape,
                                         const Standard_Integer nbx,
                                         const Standard_Integer nby,
                                         const Standard_Integer nbz,
-                                        const Standard_Integer nbthreads)
+                                        const Standard_Integer nbthreads,
+                                        const Standard_Boolean useExistingTriangulation)
 :myShape(shape),myVoxels(&voxels),
  myDeflection(deflection),
  myNbX(nbx),myNbY(nby),myNbZ(nbz),
  myNbThreads(nbthreads),myIsBool(0),
- myNbTriangles(0)
+ myNbTriangles(0),
+ myUseExistingTriangulation(useExistingTriangulation)
 {
   Init();
 }
@@ -119,14 +125,17 @@ void Voxel_FastConverter::Init()
   TopLoc_Location L;
   Standard_Boolean triangulate = Standard_False;
   TopExp_Explorer expl(myShape, TopAbs_FACE);
-  for (; expl.More(); expl.Next())
+  if(myUseExistingTriangulation == Standard_False)
   {
-    const TopoDS_Face & F = TopoDS::Face(expl.Current());
-    Handle(Poly_Triangulation) T = BRep_Tool::Triangulation(F, L);
-    if (T.IsNull() || (T->Deflection() > myDeflection))
+    for (; expl.More(); expl.Next())
     {
-      triangulate = Standard_True;
-      break;
+      const TopoDS_Face & F = TopoDS::Face(expl.Current());
+      Handle(Poly_Triangulation) T = BRep_Tool::Triangulation(F, L);
+      if (T.IsNull() || (T->Deflection() > myDeflection))
+      {
+        triangulate = Standard_True;
+        break;
+      }
     }
   }
 
@@ -167,6 +176,9 @@ Standard_Boolean Voxel_FastConverter::Convert(Standard_Integer&      progress,
   if (myNbX <= 0 || myNbY <= 0 || myNbZ <= 0)
     return Standard_False;
 
+  if(myNbTriangles == 0)
+    return Standard_False;
+
   // Half of diagonal of a voxel
   Voxel_DS* ds = (Voxel_DS*) myVoxels;
   Standard_Real dx = ds->GetXLen() / (Standard_Real) ds->GetNbX(),