0030655: Modeling Data - Provide interfaces for selection of the elements from BVH...
[occt.git] / src / BVH / BVH_BuildThread.hxx
1 // Created on: 2015-05-29
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BVH_BuildThread_Header
17 #define _BVH_BuildThread_Header
18
19 #include <OSD_Thread.hxx>
20 #include <BVH_BuildQueue.hxx>
21
22 //! Tool object to call BVH builder subroutines.
23 struct BVH_BuildTool
24 {
25   //! Performs splitting of the given BVH node.
26   virtual void Perform (const Standard_Integer theNode) = 0;
27 };
28
29 //! Wrapper for BVH build thread.
30 class BVH_BuildThread : public Standard_Transient
31 {
32   template <class T, int N> friend class BVH_QueueBuilder;
33
34 public:
35
36   //! Creates new BVH build thread.
37   Standard_EXPORT BVH_BuildThread (BVH_BuildTool& theBuildTool, BVH_BuildQueue& theBuildQueue);
38
39   //! Starts execution of BVH build thread.
40   void Run()
41   {
42     myWorkThread.Run (this);
43   }
44
45   //! Waits till the thread finishes execution.
46   void Wait()
47   {
48     myWorkThread.Wait();
49   }
50
51 protected:
52
53   //! Executes BVH build thread.
54   Standard_EXPORT void execute();
55
56   //! Thread function for BVH build thread.
57   static Standard_Address threadFunction (Standard_Address theData);
58
59   //! Assignment operator (to remove VC compile warning).
60   BVH_BuildThread& operator= (const BVH_BuildThread&);
61
62 protected:
63
64   //! Data needed to build the BVH.
65   BVH_BuildTool& myBuildTool;
66
67   //! Reference to BVH build queue.
68   BVH_BuildQueue& myBuildQueue;
69
70   //! Thread to execute work items.
71   OSD_Thread myWorkThread;
72
73 public:
74
75   DEFINE_STANDARD_RTTIEXT(BVH_BuildThread,Standard_Transient)
76 };
77
78 DEFINE_STANDARD_HANDLE (BVH_BuildThread, Standard_Transient)
79
80 #endif // _BVH_BuildThread_Header