Skip to content

Commit

Permalink
Added API function tiglFuselageGetSectionCenter (#270)
Browse files Browse the repository at this point in the history
A function for computing fuselage section center is committed.

Fixes #260
  • Loading branch information
hereToCreate authored and rainman110 committed Jul 7, 2017
1 parent 5b99a44 commit 004fbf8
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/api/tigl.cpp
Expand Up @@ -2441,6 +2441,65 @@ TIGL_COMMON_EXPORT TiglReturnCode tiglFuselageGetSegmentCount(TiglCPACSConfigura
}
}

TIGL_COMMON_EXPORT TiglReturnCode tiglFuselageGetSectionCenter(TiglCPACSConfigurationHandle cpacsHandle,
const char *fuselageSegmentUID,
double eta,
double * pointX,
double * pointY,
double * pointZ)
{
if (pointX == 0 || pointY == 0 || pointZ == 0) {
LOG(ERROR) << "Null pointer argument for pointX, pointY or pointZ\n"
<< "in function call to tiglFuselageGetSectionCenter.";
return TIGL_NULL_POINTER;
}

if (fuselageSegmentUID == NULL) {
LOG(ERROR) << "Null pointer argument for fuselageSegmentUID\n"
<< "in function call to tiglFuselageGetSectionCenter.";
return TIGL_NULL_POINTER;
}

if (eta < 0 || eta > 1) {
LOG(ERROR) << "Argument eta is not in obligatory range [0, 1]\n"
<< "in function call to tiglFuselageGetSectionCenter.";
return TIGL_MATH_ERROR;
}

try {
tigl::CCPACSConfigurationManager& manager = tigl::CCPACSConfigurationManager::GetInstance();
tigl::CCPACSConfiguration& config = manager.GetConfiguration(cpacsHandle);

// get component segment
tigl::CCPACSFuselageSegment& segment = config.GetUIDManager()
.ResolveObject<tigl::CCPACSFuselageSegment>(fuselageSegmentUID);

// get ISO curve
TopoDS_Shape curve = segment.getWireOnLoft(eta);

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

// assigne solution to return point
*pointX = centerPoint.X();
*pointY = centerPoint.Y();
*pointZ = centerPoint.Z();

}
catch (const tigl::CTiglError& ex) {
LOG(ERROR) << ex.what();
return ex.getCode();
}
catch (std::exception& ex) {
LOG(ERROR) << ex.what();
}
catch (...) {
LOG(ERROR) << "Caught an exception in tiglFuselageGetSectionCenter!";
return TIGL_ERROR;
}

return TIGL_SUCCESS;
}

TIGL_COMMON_EXPORT TiglReturnCode tiglFuselageGetPoint(TiglCPACSConfigurationHandle cpacsHandle,
int fuselageIndex,
Expand Down
23 changes: 23 additions & 0 deletions src/api/tigl.h
Expand Up @@ -1524,6 +1524,29 @@ TIGL_COMMON_EXPORT TiglReturnCode tiglFuselageGetSegmentCount(TiglCPACSConfigura
int fuselageIndex,
int* segmentCountPtr);

/**
* @brief Returns the section center of a fuselage
* @param[in] cpacsHandle Handle for the CPACS configuration
* @param[in] fuselageSegmentUID UID of the segment
* @param[in] eta Parameter value from where on the given object the section is cut out, eta in the range 0.0 <= eta <= 1.0
* @param[out] pointX Pointer to the x-coordinate of the section center point
* @param[out] pointY Pointer to the y-coordinate of the section center point
* @param[out] pointZ Pointer to the z-coordinate of the section center point
* @return
* - TIGL_SUCCESS if a point was found
* - TIGL_NOT_FOUND if no configuration was found for the given handle
* - TIGL_UID_ERROR if UID is invalid or not a fuselage segment
* - TIGL_NULL_POINTER if pointX, pointY or pointZ are null pointers
* - TIGL_MATH_ERROR if eta is out of range, i.e., not in [0, 1]
* - TIGL_ERROR if some other error occurred
*/
TIGL_COMMON_EXPORT TiglReturnCode tiglFuselageGetSectionCenter(TiglCPACSConfigurationHandle cpacsHandle,
const char *fuselageSegmentUID,
double eta,
double *pointX,
double *pointY,
double *pointZ);

/**
* @brief Returns a point on a fuselage surface for a given fuselage and segment index.
*
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
116 changes: 116 additions & 0 deletions tests/tiglFuselageSegment.cpp
Expand Up @@ -68,6 +68,47 @@ TixiDocumentHandle TiglFuselageSegment::tixiHandle = 0;
TiglCPACSConfigurationHandle TiglFuselageSegment::tiglHandle = 0;


/***************************************************************************************************/

class TiglFuselageSegmentSimple : public ::testing::Test
{
protected:
static void SetUpTestCase()
{
const char* filename = "TestData/simpletest.cpacs.xml";
ReturnCode tixiRet;
TiglReturnCode tiglRet;

tiglHandle = -1;
tixiHandle = -1;

tixiRet = tixiOpenDocument(filename, &tixiHandle);
ASSERT_TRUE (tixiRet == SUCCESS);
tiglRet = tiglOpenCPACSConfiguration(tixiHandle, "", &tiglHandle);
ASSERT_TRUE(tiglRet == TIGL_SUCCESS);
}

static void TearDownTestCase()
{
ASSERT_TRUE(tiglCloseCPACSConfiguration(tiglHandle) == TIGL_SUCCESS);
ASSERT_TRUE(tixiCloseDocument(tixiHandle) == SUCCESS);
tiglHandle = -1;
tixiHandle = -1;
}

virtual void SetUp() {}
virtual void TearDown() {}


static TixiDocumentHandle tixiHandle;
static TiglCPACSConfigurationHandle tiglHandle;
};


TixiDocumentHandle TiglFuselageSegmentSimple::tixiHandle = 0;
TiglCPACSConfigurationHandle TiglFuselageSegmentSimple::tiglHandle = 0;


/***************************************************************************************************/

/**
Expand Down Expand Up @@ -594,5 +635,80 @@ TEST_F(TiglFuselageSegment, GetSegmentVolume)
ASSERT_GT(volume, 0.);
}

/***************************************************************************************************/

TEST_F(TiglFuselageSegmentSimple, getSectionCenter)
{
// test first fuselage segment
double eta = 0.;

double pointX = 0;
double pointY = 0;
double pointZ = 0;

ASSERT_NE(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, &pointX, &pointY, &pointZ));
ASSERT_EQ(TIGL_SUCCESS, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, &pointX, &pointY, &pointZ));
EXPECT_NEAR(pointX, -0.5, 1e-15);
EXPECT_NEAR(pointY, 0, 1e-2);
EXPECT_NEAR(pointZ, 0, 1e-2);

eta = 0.5;

ASSERT_NE(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, &pointX, &pointY, &pointZ));
ASSERT_EQ(TIGL_SUCCESS, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, &pointX, &pointY, &pointZ));
EXPECT_NEAR(pointX, 0, 1e-15);
EXPECT_NEAR(pointY, 0, 1e-2);
EXPECT_NEAR(pointZ, 0, 1e-2);

eta = 1;

ASSERT_NE(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, &pointX, &pointY, &pointZ));
ASSERT_EQ(TIGL_SUCCESS, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta, &pointX, &pointY, &pointZ));
EXPECT_NEAR(pointX, 0.5, 1e-15);
EXPECT_NEAR(pointY, 0, 1e-2);
EXPECT_NEAR(pointZ, 0, 1e-2);

// test second fuselage segment
eta = 0.;

ASSERT_NE(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment3ID", eta, &pointX, &pointY, &pointZ));
ASSERT_EQ(TIGL_SUCCESS, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment3ID", eta, &pointX, &pointY, &pointZ));
EXPECT_NEAR(pointX, 0.5, 1e-15);
EXPECT_NEAR(pointY, 0, 1e-2);
EXPECT_NEAR(pointZ, 0, 1e-2);

eta = 0.5;

ASSERT_NE(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment3ID", eta, &pointX, &pointY, &pointZ));
ASSERT_EQ(TIGL_SUCCESS, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment3ID", eta, &pointX, &pointY, &pointZ));
EXPECT_NEAR(pointX, 1, 1e-15);
EXPECT_NEAR(pointY, 0, 1e-2);
EXPECT_NEAR(pointZ, 0, 1e-2);

eta = 1;

ASSERT_NE(TIGL_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment3ID", eta, &pointX, &pointY, &pointZ));
ASSERT_EQ(TIGL_SUCCESS, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment3ID", eta, &pointX, &pointY, &pointZ));
EXPECT_NEAR(pointX, 1.5, 1e-15);
EXPECT_NEAR(pointY, 0, 1e-2);
EXPECT_NEAR(pointZ, 0, 1e-2);

// some other tests: make sure that right error codes are returned in case of the corresponding errors
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_NULL_POINTER, tiglFuselageGetSectionCenter(tiglHandle, NULL, eta, &pointX, &pointY, &pointZ));

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

double eta_out_of_range = -0.5;
ASSERT_EQ(TIGL_MATH_ERROR, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta_out_of_range, &pointX, &pointY, &pointZ));
eta_out_of_range = 2;
ASSERT_EQ(TIGL_MATH_ERROR, tiglFuselageGetSectionCenter(tiglHandle, "segmentD150_Fuselage_1Segment2ID", eta_out_of_range, &pointX, &pointY, &pointZ));
}

0 comments on commit 004fbf8

Please sign in to comment.