Skip to content

Commit

Permalink
Merge pull request #1065 from DLR-SC/1064-request-add-api-function-ti…
Browse files Browse the repository at this point in the history
…glcomponenttransformpointtoglobal-to-transform-a-point-in-local-coordinate-systems-to-the-global

Added the function tiglComponentTransformPointToGlobal to transform a point in local coordinate systems to the global
  • Loading branch information
joergbrech authored Mar 6, 2025
2 parents c63dc34 + 8d4cec1 commit 654210a
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 5 deletions.
7 changes: 6 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ Changes since last release
10/01/2025

- Fixes

- #936 A particular defined positioning (of the C++-type CCPACSPositioning) was not available via Python bindings since the std::vector<std::unique_ptr<**Type**>> is not exposed to swig. New getter functions have been implemented in CCPACSPositioning.h to make these elements accesible via index, similar to the implementation of for several other classes. For more information see https://github.com/RISCSoftware/cpacs_tigl_gen/issues/59.

- New API functions:

- New function `::tiglComponentTransformPointToGlobal` to transform component-local coordinates into global coordinates (#1064)

- General changes:
- General changes:

- Update the C++ standard to C++17 (#1045).
- Added the possibility to switch between two algorithms in the `CCSTCurveBuilder`. The default algorithm based on a Chebychev approximation results in a small number of control points, but introduces small discontinuities in the curvature. The new option is to use OCCT's `GeomAPI_PointsToBSpline`, which results in a C3 continuous B-Spline.

Expand Down
17 changes: 17 additions & 0 deletions TIGLViewer/src/TIGLScriptProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,23 @@ QScriptValue TIGLScriptProxy::wingGetSegmentEtaXsi(int wingIdx, double px, doubl

}

QScriptValue TIGLScriptProxy::componentTransformPointToGlobal(QString componentUID, double localX, double localY, double localZ)
{
double gx, gy, gz;

TiglReturnCode ret = ::tiglComponentTransformPointToGlobal(getTiglHandle(), componentUID.toStdString().c_str(),
localX, localY, localZ,
&gx, &gy, &gz);

if (ret != TIGL_SUCCESS) {
return context()->throwError(tiglGetErrorString(ret));
}
else {
QScriptValue Point3dCtor = engine()->globalObject().property("Point3d");
return Point3dCtor.construct(QScriptValueList() << gx << gy << gz);
}
}


QScriptValue TIGLScriptProxy::getShape(QString uid)
{
Expand Down
6 changes: 6 additions & 0 deletions TIGLViewer/src/TIGLScriptProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public slots:
QScriptValue wingGetSegmentEtaXsi(int wingIdx, double px, double py, double pz);


// Component
QScriptValue componentTransformPointToGlobal(QString componentUID,
double localX,
double localY,
double localZ);

QString getErrorString(int errorCode);
QScriptValue getShape(QString uid);

Expand Down
62 changes: 62 additions & 0 deletions src/api/tigl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7529,3 +7529,65 @@ TiglReturnCode tiglConfigurationGetWithDuctCutouts(TiglCPACSConfigurationHandle
return TIGL_ERROR;
}
}

TiglReturnCode tiglComponentTransformPointToGlobal(TiglCPACSConfigurationHandle cpacsHandle,
const char *componentUID,
double localX,
double localY,
double localZ,
double *globalX,
double *globalY,
double *globalZ)
{
if (!componentUID) {
LOG(ERROR) << "Null pointer for argument componentUID in tiglComponentTransformPointToGlobal";
return TIGL_NULL_POINTER;
}

if (!globalX) {
LOG(ERROR) << "Null pointer for argument globalX in tiglComponentTransformPointToGlobal";
return TIGL_NULL_POINTER;
}


if (!globalY) {
LOG(ERROR) << "Null pointer for argument globalY in tiglComponentTransformPointToGlobal";
return TIGL_NULL_POINTER;
}

if (!globalZ) {
LOG(ERROR) << "Null pointer for argument globalZ in tiglComponentTransformPointToGlobal";
return TIGL_NULL_POINTER;
}


try {
// try to resolve the object for the given uid and get the flag
tigl::CCPACSConfigurationManager& manager = tigl::CCPACSConfigurationManager::GetInstance();
tigl::CCPACSConfiguration& config = manager.GetConfiguration(cpacsHandle);

tigl::CTiglRelativelyPositionedComponent& component = config.GetUIDManager().GetRelativeComponent(componentUID);

gp_Pnt pGlobal = component.GetTransformationMatrix().Transform(gp_Pnt(localX, localY, localZ));

*globalX = pGlobal.X();
*globalY = pGlobal.Y();
*globalZ = pGlobal.Z();


return TIGL_SUCCESS;

}
catch (const tigl::CTiglError& ex) {
LOG(ERROR) << ex.what();
return ex.getCode();
}
catch (std::exception& ex) {
LOG(ERROR) << ex.what();
return TIGL_ERROR;
}
catch (...) {
LOG(ERROR) << "Caught an exception in tiglComponentTransformPointToGlobal!";
return TIGL_ERROR;
}
}
23 changes: 23 additions & 0 deletions src/api/tigl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5028,6 +5028,29 @@ TIGL_COMMON_EXPORT TiglReturnCode tiglComponentGetType(TiglCPACSConfigurationHan
const char* componentUID,
TiglGeometricComponentType* typePtr);

/**
* @brief Transforms a local point in a component to the global coordinate system
*
* @param[in] cpacsHandle Handle for the CPACS configuration
* @param[in] componentUID The uid of the component for which the hash should be computed
* @param[in] localX X-Coordinate of the local point
* @param[in] localY Y-Coordinate of the local point
* @param[in] localZ Z-Coordinate of the local point
* @param[out] globalX X-Coordinate of the result in global coordinates
* @param[out] globalY Y-Coordinate of the result in global coordinates
* @param[out] globalZ Z-Coordinate of the result in global coordinates
*
* @return
* - TIGL_SUCCESS if no error occurred
* - TIGL_NOT_FOUND if no configuration was found for the given handle
* - TIGL_UID_ERROR if the uid is invalid or not a known geometric component
*
*/
TIGL_COMMON_EXPORT TiglReturnCode tiglComponentTransformPointToGlobal(TiglCPACSConfigurationHandle cpacsHandle,
const char* componentUID,
double localX, double localY, double localZ,
double* globalX, double* globalY, double* globalZ);

/**
* @brief Translates an error code into a string
*
Expand Down
4 changes: 2 additions & 2 deletions src/cpacs_other/CTiglUIDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,12 @@ ITiglGeometricComponent& CTiglUIDManager::GetGeometricComponent(const std::strin
CTiglRelativelyPositionedComponent& CTiglUIDManager::GetRelativeComponent(const std::string& uid) const
{
if (uid.empty()) {
throw CTiglError("Empty UID in CTiglUIDManager::GetGeometricComponent", TIGL_XML_ERROR);
throw CTiglError("Empty UID in CTiglUIDManager::GetGeometricComponent", TIGL_UID_ERROR);
}

const RelativeComponentContainerType::const_iterator it = relativeComponents.find(uid);
if (it == relativeComponents.end()) {
throw CTiglError("UID '"+uid+"' not found in CTiglUIDManager::GetGeometricComponent", TIGL_XML_ERROR);
throw CTiglError("UID '"+uid+"' not found in CTiglUIDManager::GetGeometricComponent", TIGL_UID_ERROR);
}

return *it->second;
Expand Down
5 changes: 3 additions & 2 deletions src/cpacs_other/CTiglUIDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class CTiglUIDManager
// Returns the parent component for a component or a null pointer if there is no parent.
TIGL_EXPORT CTiglRelativelyPositionedComponent* GetParentGeometricComponent(const std::string& uid) const;

// Returns a pointer to the geometric component for the given unique id.
TIGL_EXPORT CTiglRelativelyPositionedComponent& GetRelativeComponent(const std::string& uid) const;

// Returns the container with all root components of the geometric topology that have children.
TIGL_EXPORT const RelativeComponentContainerType& GetRootGeometricComponents() const;

Expand Down Expand Up @@ -170,8 +173,6 @@ class CTiglUIDManager
// Builds the parent child relationships and finds the root components
void BuildTree();

// Returns a pointer to the geometric component for the given unique id.
CTiglRelativelyPositionedComponent& GetRelativeComponent(const std::string& uid) const;

private:
typedef std::map<std::string, TypedPtr> CPACSObjectMap;
Expand Down
42 changes: 42 additions & 0 deletions tests/unittests/tiglTransformationBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,45 @@ TEST_F(TiglTransformationBenchmark, checkProfilePositions)
EXPECT_NEAR(3.0, py, 1e-10);
EXPECT_NEAR(0.0, pz, 1e-10);
}

TEST_F(TiglTransformationBenchmark, transformPointToGlobal)
{
double px, py, pz;

ASSERT_EQ(TIGL_SUCCESS, tiglComponentTransformPointToGlobal(tiglHandle, "Wing0", 0., 0., 0., &px, &py, &pz));
EXPECT_NEAR(1.0, px, 1e-10);
EXPECT_NEAR(0.0, py, 1e-10);
EXPECT_NEAR(0.0, pz, 1e-10);

ASSERT_EQ(TIGL_SUCCESS, tiglComponentTransformPointToGlobal(tiglHandle, "Wing1", 0., 0., 0., &px, &py, &pz));
EXPECT_NEAR(1.0, px, 1e-10);
EXPECT_NEAR(1.0, py, 1e-10);
EXPECT_NEAR(0.0, pz, 1e-10);

ASSERT_EQ(TIGL_SUCCESS, tiglComponentTransformPointToGlobal(tiglHandle, "Wing2", 0., 0., 0., &px, &py, &pz));
EXPECT_NEAR(1.5, px, 1e-10);
EXPECT_NEAR(2.0, py, 1e-10);
EXPECT_NEAR(0.0, pz, 1e-10);

ASSERT_EQ(TIGL_SUCCESS, tiglComponentTransformPointToGlobal(tiglHandle, "Wing3", 0., 0., 0., &px, &py, &pz));
EXPECT_NEAR(1.5, px, 1e-10);
EXPECT_NEAR(3.0, py, 1e-10);
EXPECT_NEAR(0.0, pz, 1e-10);
}

TEST_F(TiglTransformationBenchmark, transformPointToGlobalErrors)
{
double px, py, pz;

// Invalid handle
EXPECT_EQ(TIGL_NOT_FOUND, tiglComponentTransformPointToGlobal(-1, "Wing3", 0., 0., 0., &px, &py, &pz));

// Invalid UUID
EXPECT_EQ(TIGL_UID_ERROR, tiglComponentTransformPointToGlobal(tiglHandle, "UUID_NOT_EXIST", 0, 0., 0., &px, &py, &pz));

// nullptrs
EXPECT_EQ(TIGL_NULL_POINTER, tiglComponentTransformPointToGlobal(tiglHandle, nullptr, 0., 0., 0., &px, &py, &pz));
EXPECT_EQ(TIGL_NULL_POINTER, tiglComponentTransformPointToGlobal(tiglHandle, "Wing3", 0., 0., 0., nullptr, &py, &pz));
EXPECT_EQ(TIGL_NULL_POINTER, tiglComponentTransformPointToGlobal(tiglHandle, "Wing3", 0., 0., 0., &px, nullptr, &pz));
EXPECT_EQ(TIGL_NULL_POINTER, tiglComponentTransformPointToGlobal(tiglHandle, "Wing3", 0., 0., 0., &px, &py, nullptr));
}

0 comments on commit 654210a

Please sign in to comment.