-
Notifications
You must be signed in to change notification settings - Fork 1
/
OpenCascadeSphereExample.cpp
105 lines (83 loc) · 3.36 KB
/
OpenCascadeSphereExample.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <TopoDS_Shape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <gp_Pnt.hxx>
#include <iostream>
#include <vtkNew.h>
#include <vtkXMLPolyDataWriter.h>
#include "vtk.h"
#include "triangulate.h"
#include "tbb/task_scheduler_init.h"
#include <chrono>
void cutOperation (const std::string& filename)
{
auto start_time = std::chrono::high_resolution_clock::now();
TopoDS_Shape left = BRepPrimAPI_MakeBox(21.5,21.5,1.0).Shape();
TopTools_ListOfShape aLS;
aLS.Append(left);
TopTools_ListOfShape aLT;
for(int i = 1;i<21;++i)
{
for(int j = 1;j<21;++j)
{
aLT.Append(BRepPrimAPI_MakeSphere(gp_Pnt(static_cast<double>(i)+0.25,static_cast<double>(j)+0.25,0.0),0.5).Shape());
}
}
BRepAlgoAPI_Cut aBuilder;
// set the arguments
aBuilder.SetArguments(aLS);
aBuilder.SetTools(aLT);
// set parallel processing mode
// if bRunParallel= Standard_True : the parallel processing is switched on
// if bRunParallel= Standard_False : the parallel processing is switched off
Standard_Boolean bRunParallel=Standard_True;
aBuilder.SetRunParallel(bRunParallel);
// set Fuzzy value
// if aFuzzyValue=0.: the Fuzzy option is off
// if aFuzzyValue>0.: the Fuzzy option is on
Standard_Real aFuzzyValue=2.1e-5;
aBuilder.SetFuzzyValue(aFuzzyValue);
auto end_time = std::chrono::high_resolution_clock::now();
cout << "construction time: " << std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count() << " microseconds\n";
start_time = std::chrono::high_resolution_clock::now();
// run the algorithm
aBuilder.Build();
Standard_Integer iErr = aBuilder.ErrorStatus();
if (iErr)
{
// an error treatment
return;
}
TopoDS_Shape Result = aBuilder.Shape();
end_time = std::chrono::high_resolution_clock::now();
cout << "build time: " << std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count() << " microseconds\n";
start_time = std::chrono::high_resolution_clock::now();
VTK_Helper helper;
vtkSmartPointer<vtkPolyData> polydata = helper.cascade_to_vtk(triangulate(Result));
end_time = std::chrono::high_resolution_clock::now();
cout << "triangulation time: " << std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count() << " microseconds\n";
start_time = std::chrono::high_resolution_clock::now();
vtkNew<vtkXMLPolyDataWriter> writer;
writer->SetFileName(filename.c_str());
writer->SetInputData(polydata.GetPointer());
writer->Write();
end_time = std::chrono::high_resolution_clock::now();
cout << "writer time: " << std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count() << " microseconds\n";
}
int main()
{
int maxThreads = tbb::task_scheduler_init::default_num_threads();
for(int i = maxThreads;i>0;--i)
{
cout << i << " threads\n";
tbb::task_scheduler_init init(i);
auto start_time = std::chrono::high_resolution_clock::now();
cutOperation("test_"+std::to_string(i)+".vtp");
auto end_time = std::chrono::high_resolution_clock::now();
cout << "total time: " << std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count() << " microseconds\n";
}
return 0;
}