Skip to content

Commit

Permalink
Fixes for API function tiglFuselageGetSectionCenter
Browse files Browse the repository at this point in the history
Some lines in tiglFuselageGetSectionCenter are bundled in a helper
function. The test for this method is enhanced.

Fixes issue DLR-SC#260
  • Loading branch information
Merlin Pelz committed Jul 6, 2017
1 parent c1ee4ea commit 363cd5d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
8 changes: 1 addition & 7 deletions src/api/tigl.cpp
Expand Up @@ -62,8 +62,6 @@
#include "gp_Pnt.hxx"
#include "TopoDS_Shape.hxx"
#include "TopoDS_Edge.hxx"
#include "GProp_GProps.hxx"
#include "BRepGProp.hxx"

/*****************************************************************************/
/* Private functions. */
Expand Down Expand Up @@ -2467,12 +2465,8 @@ TIGL_COMMON_EXPORT TiglReturnCode tiglFuselageGetSectionCenter(TiglCPACSConfigur
// get ISO curve
TopoDS_Shape curve = segment.getWireOnLoft(eta);

// get linear properties of the ISO curve
GProp_GProps LProps;
BRepGProp::LinearProperties(curve, LProps);

// compute center of the ISO curve
gp_Pnt centerPoint = LProps.CentreOfMass();
gp_Pnt centerPoint = GetCenterOfMass(curve);

// assigne solution to return point
*pointX = centerPoint.X();
Expand Down
14 changes: 14 additions & 0 deletions src/common/tiglcommonfunctions.cpp
Expand Up @@ -65,6 +65,8 @@
#include "BRepBndLib.hxx"
#include "BRepExtrema_ExtCF.hxx"
#include "BRepFill.hxx"
#include "GProp_GProps.hxx"
#include "BRepGProp.hxx"

#include <Approx_Curve3d.hxx>
#include <BRepAdaptor_HCompCurve.hxx>
Expand Down Expand Up @@ -1074,6 +1076,18 @@ TopoDS_Face GetNearestFace(const TopoDS_Shape& shape, const gp_Pnt& pnt)
return resultFace;
}

gp_Pnt GetCenterOfMass(const TopoDS_Shape &shape)
{
// get linear properties of the shape
GProp_GProps LProps;
BRepGProp::LinearProperties(shape, LProps);

// compute center of the shape
gp_Pnt centerPoint = LProps.CentreOfMass();

return centerPoint;
}

TopoDS_Shape RemoveDuplicateEdges(const TopoDS_Shape& shape)
{
TopTools_ListOfShape initialEdgeList, newEdgeList;
Expand Down
3 changes: 3 additions & 0 deletions src/common/tiglcommonfunctions.h
Expand Up @@ -191,6 +191,9 @@ TIGL_EXPORT void GetEndVertices(const TopoDS_Shape& shape, TopTools_ListOfShape&
// Method for finding the face which has the lowest distance to the passed point
TIGL_EXPORT TopoDS_Face GetNearestFace(const TopoDS_Shape& src, const gp_Pnt& pnt);

// Method for finding the center of mass of a shape
TIGL_EXPORT gp_Pnt GetCenterOfMass(const TopoDS_Shape& shape);

// Method for checking for duplicate edges in the passed shape.
// The method returns a shape with only unique edges
// NOTE: THIS METHOD ONLY CHECKS THE VERTEX POSITIONS, AND THE MIDDLE POINT
Expand Down
10 changes: 9 additions & 1 deletion tests/tiglFuselageSegment.cpp
Expand Up @@ -667,7 +667,15 @@ TEST_F(TiglFuselageSegmentSimple, getSectionCenter)
EXPECT_NEAR(pointY, 0, 1e-2);
EXPECT_NEAR(pointZ, 0, 1e-2);

ASSERT_EQ(TIGL_UID_ERROR, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselaggg_1Segment2ID", eta, &pointX, &pointY, &pointZ));
ASSERT_EQ(TIGL_UID_ERROR, tiglFuselageGetSectionCenter(tiglHandle, "invalidUID", eta, &pointX, &pointY, &pointZ));

ASSERT_EQ(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, NULL, &pointY, &pointZ));
ASSERT_EQ(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, &pointX, NULL, &pointZ));
ASSERT_EQ(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, &pointX, &pointY, NULL));
ASSERT_EQ(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, NULL, NULL, &pointZ));
ASSERT_EQ(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, &pointX, NULL, NULL));
ASSERT_EQ(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, NULL, NULL, NULL));

ASSERT_EQ(TIGL_NOT_FOUND, tiglFuselageGetSectionCenter(-1, "segmentD150_Fuselage_1Segment2ID", eta, &pointX, &pointY, &pointZ));
}

0 comments on commit 363cd5d

Please sign in to comment.