Skip to content

Commit

Permalink
Merge pull request #999 from DLR-SC/MakeAddSideCapsThrowException
Browse files Browse the repository at this point in the history
Made Lofting algorithm throw Exception when side caps are invalid
  • Loading branch information
joergbrech authored Aug 30, 2024
2 parents 52cdb0e + 6c4fd02 commit 28b2dc3
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/geometry/CTiglPatchShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include <StdFail_NotDone.hxx>
#include <BRepBuilderAPI_Sewing.hxx>
#include <Geom_Plane.hxx>
#include <BRepCheck_Analyzer.hxx>

#include "CTiglLogging.h"
#include "CTiglLogSplitter.h"

namespace
{
Expand Down Expand Up @@ -70,6 +74,11 @@ void CTiglPatchShell::AddSideCap(TopoDS_Wire const& boundaryWire)
BRepBuilderAPI_FindPlane Searcher( boundaryWire, _tolerance );
if (Searcher.Found()) {
cap = BRepBuilderAPI_MakeFace(Searcher.Plane(), boundaryWire);
#ifdef DEBUG
if(!BRepCheck_Analyzer(cap).IsValid()){
LOG(WARNING) << "WARNING: Side caps invalid.";
}
#endif
Ok = true;
}
else {
Expand All @@ -78,6 +87,11 @@ void CTiglPatchShell::AddSideCap(TopoDS_Wire const& boundaryWire)
if (MF.IsDone())
{
cap = MF.Face();
#ifdef DEBUG
if(!BRepCheck_Analyzer(cap).IsValid()){
LOG(WARNING) << "WARNING: Side caps invalid.";
}
#endif
Ok = true;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/logging/CTiglLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ void CTiglLogging::SetConsoleVerbosity(TiglLogLevel vlevel)
}
}


TiglLogLevel CTiglLogging::GetConsoleVerbosity() const

{
return _consoleVerbosity;
}
Expand Down
1 change: 1 addition & 0 deletions src/logging/CTiglLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class CTiglLogging
TIGL_EXPORT void SetTimeIdInFilenameEnabled(bool enabled);
TIGL_EXPORT void LogToConsole();
TIGL_EXPORT void SetConsoleVerbosity(TiglLogLevel vlevel);

TIGL_EXPORT TiglLogLevel GetConsoleVerbosity() const;

// allows installing a custom log sink/receiver
Expand Down
49 changes: 48 additions & 1 deletion tests/unittests/testCTiglPatchShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
* limitations under the License.
*/

#include "CTiglConsoleLogger.h"
#include "CTiglFileLogger.h"
#include "CTiglLogSplitter.h"
#include "test.h"
#include "BRepBuilderAPI_Transform.hxx"
#include "CTiglMakeLoft.h"
#include "CTiglPatchShell.h"
#include "CTiglError.h"
#include "CTiglPointsToBSplineInterpolation.h"
Expand All @@ -26,6 +31,8 @@
#include "BRepBuilderAPI_MakeFace.hxx"
#include "BRep_Builder.hxx"

#include "CTiglLogging.h"
#include "testUtils.h"

TEST(CTiglPatchShell, Success)
{
Expand Down Expand Up @@ -54,7 +61,7 @@ TEST(CTiglPatchShell, Success)
pnt2->SetValue(4, gp_Pnt(0., -1., 5.));
pnt2->SetValue(5, gp_Pnt(1., 0., 5.));

// interpoate points to curve
// interpolate points to curve
tigl::CTiglPointsToBSplineInterpolation app2(pnt2, 3, true);
Handle(Geom_BSplineCurve) tip_curve = app2.Curve();
gp_Trsf T;
Expand Down Expand Up @@ -90,3 +97,43 @@ TEST(CTiglPatchShell, brokenShape)
tigl::CTiglPatchShell patcher(brokenShape, 1e-6);
EXPECT_THROW(patcher.PatchedShape();, tigl::CTiglError);
}

TEST(CTiglPatchShell, noSideCaps)
{
#ifdef DEBUG
//define coordinates for profile wire enclosing two unconnected surface areas
std::vector<gp_Pnt> points = {gp_Pnt(0., 0., 0.),gp_Pnt(0., 0.,1.),gp_Pnt(0.,0.5,0.),
gp_Pnt(0.,1.,1.), gp_Pnt(0., 1.,0.), gp_Pnt(0.,0.,0.)};

//build 1st wire
BRepBuilderAPI_MakeWire wire1;
for(int i=0; i < points.size()-1; i++){
auto edge = BRepBuilderAPI_MakeEdge(points[i],points[i+1]).Edge();
wire1.Add(edge);
}

//build 2nd wire
auto trafo = gp_Trsf();
auto vec = gp_Vec(-1.,0.,0.);
trafo.SetTranslation(vec);
auto wire2 = BRepBuilderAPI_Transform(wire1.Shape(), trafo);

//lofting should throw exception building (no) side caps for given profile wire
auto loft = CTiglMakeLoft();
loft.addProfiles(wire1.Shape());
loft.addProfiles(wire2.Shape());

// Check for warning
{ // Scope to destroy object of type CaptureTiGLLog and therefore reset console verbosity
CaptureTiGLLog t{TILOG_WARNING};

//call function that returns warning
loft.Shape();

auto logOutput = t.log();

std::string comparisonString = "WARNING: Side caps invalid.";
ASSERT_TRUE((logOutput.find(comparisonString)) != std::string::npos);
} // scope
#endif
}

0 comments on commit 28b2dc3

Please sign in to comment.