Skip to content

Commit

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

Fixes issue DLR-SC#260
  • Loading branch information
Merlin Pelz committed Jul 6, 2017
1 parent 5b99a44 commit c1ee4ea
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/api/tigl.cpp
Expand Up @@ -62,6 +62,8 @@
#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 @@ -2441,6 +2443,58 @@ 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;
}

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);

// 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();

// 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
21 changes: 21 additions & 0 deletions src/api/tigl.h
Expand Up @@ -1523,6 +1523,27 @@ TIGL_COMMON_EXPORT TiglReturnCode tiglGetFuselageCount(TiglCPACSConfigurationHan
TIGL_COMMON_EXPORT TiglReturnCode tiglFuselageGetSegmentCount(TiglCPACSConfigurationHandle cpacsHandle,
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_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
75 changes: 75 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,39 @@ TEST_F(TiglFuselageSegment, GetSegmentVolume)
ASSERT_GT(volume, 0.);
}

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

TEST_F(TiglFuselageSegmentSimple, getSectionCenter)
{
double eta = 0.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);

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

0 comments on commit c1ee4ea

Please sign in to comment.