0025039: Improvement of code structure of general and supporting tools implemented...
[occt.git] / src / BRepMesh / BRepMesh_FaceChecker.hxx
CommitLineData
9bdafcbe 1// Created on: 2014-05-28
2// Created by: Oleg AGASHIN
3// Copyright (c) 2011-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 _BRepMesh_FaceChecker_HeaderFile
17#define _BRepMesh_FaceChecker_HeaderFile
18
19#include <Standard.hxx>
20#include <Standard_Mutex.hxx>
fc9b36d6 21#include <TopoDS.hxx>
9bdafcbe 22#include <TopoDS_Face.hxx>
23#include <TopoDS_Edge.hxx>
24#include <TopLoc_Location.hxx>
25#include <Poly_Triangulation.hxx>
26#include <TopExp_Explorer.hxx>
27#include <BRepMesh_EdgeChecker.hxx>
28
29#include <vector>
30
31#ifdef HAVE_TBB
32 // paralleling using Intel TBB
33 #include <tbb/parallel_for_each.h>
34#endif
35
36//! Auxilary class implementing functionality for
37//! checking consistency of triangulation on the given face.
38class BRepMesh_FaceChecker
39{
40public:
41
42 //! Constructor
43 //! \param isInParallel Flag indicates that face edges should be checked in parallel.
44 BRepMesh_FaceChecker(const Standard_Boolean isInParallel)
45 : myIsFailed(Standard_False),
46 myIsInParallel(isInParallel)
47 {
48 }
49
50 //! Checker's body.
51 //! \param theFace Face to be checked.
52 void operator ()(const TopoDS_Face& theFace) const
53 {
54 if (theFace.IsNull() || myIsFailed)
55 return;
56
57 TopLoc_Location aFaceLoc;
58 Handle(Poly_Triangulation) aFaceT =
59 BRep_Tool::Triangulation(theFace, aFaceLoc);
60
61 if (aFaceT.IsNull())
62 return;
63
64 std::vector<TopoDS_Edge> aEdges;
65 TopExp_Explorer aEdgeIt(theFace, TopAbs_EDGE);
66 for ( ; aEdgeIt.More(); aEdgeIt.Next())
67 aEdges.push_back(TopoDS::Edge(aEdgeIt.Current()));
68
69 BRepMesh_EdgeChecker aEdgeChecker(aFaceT, aFaceLoc, myMutex, myIsFailed);
fc9b36d6 70#ifdef HAVE_TBB
9bdafcbe 71 if (myIsInParallel)
72 {
9bdafcbe 73 // check faces in parallel threads using TBB
74 tbb::parallel_for_each(aEdges.begin(), aEdges.end(), aEdgeChecker);
9bdafcbe 75 }
76 else
77 {
fc9b36d6 78#endif
9bdafcbe 79 for (std::vector<TopoDS_Edge>::iterator it(aEdges.begin()); it != aEdges.end(); it++)
80 aEdgeChecker(*it);
fc9b36d6 81#ifdef HAVE_TBB
9bdafcbe 82 }
fc9b36d6 83#endif
9bdafcbe 84 }
85
86 //! Returns status of the check.
87 Standard_Boolean IsValid() const
88 {
89 return !myIsFailed;
90 }
91
92private:
93 mutable Standard_Mutex myMutex;
94 mutable Standard_Boolean myIsFailed;
95 Standard_Boolean myIsInParallel;
96};
97
98#endif