Skip to content

Commit

Permalink
New functions:
Browse files Browse the repository at this point in the history
- tiglWingComponentSegmentFindSegment -- returns the segmentUID and wingUID for a given point on a componentSegment
- tiglWingComponentSegmentPointGetSegmentEtaXsir -- eturns eta, xsi, segmentUID and wingUID for a given eta and xsi on a componentSegment
  • Loading branch information
markus.litz committed Mar 8, 2012
1 parent ba94c54 commit 6a56304
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 33 deletions.
6 changes: 6 additions & 0 deletions Src/CCPACSWing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ namespace tigl {
return (ITiglSegment &) segments.GetSegment(index);
}

// Returns the segment for a given uid
ITiglSegment & CCPACSWing::GetSegment(std::string uid)
{
return (ITiglSegment &) segments.GetSegment(uid);
}

// Get componentSegment count
int CCPACSWing::GetComponentSegmentCount(void)
{
Expand Down
3 changes: 2 additions & 1 deletion Src/CCPACSWing.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ namespace tigl {
// Get segment count
int GetSegmentCount(void);

// Returns the segment for a given index
// Returns the segment for a given index or uid
ITiglSegment & GetSegment(const int index);
ITiglSegment & GetSegment(std::string uid);

// Get segment count
int GetComponentSegmentCount(void);
Expand Down
112 changes: 100 additions & 12 deletions Src/CCPACSWingComponentSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
#include "Geom_BSplineSurface.hxx"
#include "GeomAPI_ProjectPointOnSurf.hxx"
#include "BRepClass3d_SolidClassifier.hxx"
#include "BRepAdaptor_CompCurve.hxx"
#include "BRepExtrema_DistShapeShape.hxx"
#include "GCPnts_AbscissaPoint.hxx"


#ifndef max
Expand Down Expand Up @@ -293,18 +296,103 @@ namespace tigl {
}


// // Gets the upper point in relative wing coordinates for a given eta and xsi
// gp_Pnt CCPACSWingComponentSegment::GetUpperPoint(double eta, double xsi)
// {
// return GetPoint(eta, xsi, true);
// }
//
// // Gets the lower point in relative wing coordinates for a given eta and xsi
// gp_Pnt CCPACSWingComponentSegment::GetLowerPoint(double eta, double xsi)
// {
// return GetPoint(eta, xsi, false);
// }
//
// Gets a point in relative wing coordinates for a given eta and xsi
gp_Pnt CCPACSWingComponentSegment::GetPoint(double eta, double xsi)
{
// search for ETA coordinate
std::vector<gp_Pnt> CPointContainer;
std::vector<gp_Pnt> CPointContainer2d;
bool inComponentSection = false;

if (eta < 0.0 || eta > 1.0)
{
throw CTiglError("Error: Parameter eta not in the range 0.0 <= eta <= 1.0 in CCPACSWingComponentSegment::GetPoint", TIGL_ERROR);
}
if (xsi < 0.0 || xsi > 1.0)
{
throw CTiglError("Error: Parameter xsi not in the range 0.0 <= xsi <= 1.0 in CCPACSWingComponentSegment::GetPoint", TIGL_ERROR);
}

for (int i = 1; i <= wing->GetSegmentCount(); i++)
{
tigl::CCPACSWingSegment& segment = (tigl::CCPACSWingSegment &) wing->GetSegment(i);


// if we found the outer section, break...
if( (segment.GetInnerSectionElementUID() == toElementUID) || (segment.GetOuterSectionElementUID() == toElementUID)) {
gp_Pnt pnt = segment.GetPoint(0, xsi, true);
pnt = wing->GetWingTransformation().Transform(pnt);
CPointContainer.push_back(pnt);

pnt = segment.GetPoint(1, xsi, true);
pnt = wing->GetWingTransformation().Transform(pnt);
CPointContainer.push_back(pnt);

i++;
break;
}

// Ok, we found the first segment of this componentSegment
if(segment.GetInnerSectionElementUID() == fromElementUID) {
inComponentSection = true;
}

// try next segment if this is not within the componentSegment
if (!inComponentSection) continue;

gp_Pnt pnt = segment.GetPoint(0, xsi, true);
pnt = wing->GetWingTransformation().Transform(pnt);
CPointContainer.push_back(pnt);
}


// make all point in 2d because its only a projection
for (int j = 0; j < CPointContainer.size(); j++)
{
gp_Pnt pnt = CPointContainer[j];
pnt = gp_Pnt(0, pnt.Y(), pnt.Z());
CPointContainer2d.push_back(pnt);
}


// build virtual ETA-line
BRepBuilderAPI_MakeWire wireBuilder;
for (int j = 1; j < CPointContainer2d.size(); j++)
{
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(CPointContainer2d[j - 1], CPointContainer2d[j]);
wireBuilder.Add(edge);
}
TopoDS_Wire etaLinie = wireBuilder.Wire();

// build virtual XSI-line
BRepBuilderAPI_MakeWire wireBuilderXsi;
for (int j = 1; j < CPointContainer.size(); j++)
{
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(CPointContainer[j - 1], CPointContainer[j]);
wireBuilderXsi.Add(edge);
}
TopoDS_Wire xsiLinie = wireBuilderXsi.Wire();

// ETA 3D point
BRepAdaptor_CompCurve aCompoundCurve(etaLinie, Standard_True);
gp_Pnt etaPnt;

Standard_Real len = GCPnts_AbscissaPoint::Length( aCompoundCurve );
aCompoundCurve.D0( len * eta, etaPnt );


// intersection line
Handle(Geom_TrimmedCurve) profileLine = GC_MakeSegment(etaPnt, gp_Pnt(1e9, 0, 0));
BRepBuilderAPI_MakeEdge ME(profileLine);
TopoDS_Shape aCrv(ME.Edge());

//intersection point
BRepExtrema_DistShapeShape extrema(xsiLinie, aCrv);
extrema.Perform();

return extrema.PointOnShape1(1);
}


// Returns the volume of this segment
double CCPACSWingComponentSegment::GetVolume(void)
Expand Down
7 changes: 2 additions & 5 deletions Src/CCPACSWingComponentSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ namespace tigl {
// Gets the loft between the two segment sections
TopoDS_Shape GetLoft(void);

// // Gets the upper point in relative wing coordinates for a given eta and xsi
// gp_Pnt GetUpperPoint(double eta, double xsi);
//
// // Gets the lower point in relative wing coordinates for a given eta and xsi
// gp_Pnt GetLowerPoint(double eta, double xsi);
// Gets a point in relative wing coordinates for a given eta and xsi
gp_Pnt GetPoint(double eta, double xsi);

// Gets the volume of this segment
double GetVolume();
Expand Down
48 changes: 47 additions & 1 deletion Src/CCPACSWingSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
#include "GeomFill_FillingStyle.hxx"
#include "Geom_BSplineSurface.hxx"
#include "GeomAPI_ProjectPointOnSurf.hxx"

#include "BRepExtrema_DistShapeShape.hxx"
#include "GCPnts_AbscissaPoint.hxx"
#include "BRepAdaptor_CompCurve.hxx"

#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
Expand Down Expand Up @@ -555,6 +557,50 @@ namespace tigl {
return uid.c_str();
}


double CCPACSWingSegment::GetEta(gp_Pnt pnt, double xsi)
{
// Build virtual eta line.
// eta is in x = 0
gp_Pnt pnt0 = GetPoint(0, xsi, true);
pnt0 = wing->GetWingTransformation().Transform(pnt0);
pnt0 = gp_Pnt(0, pnt0.Y(), pnt0.Z());

gp_Pnt pnt1 = GetPoint(1, xsi, true);
pnt1 = wing->GetWingTransformation().Transform(pnt1);
pnt1 = gp_Pnt(0, pnt1.Y(), pnt1.Z());

BRepBuilderAPI_MakeWire etaWireBuilder;
TopoDS_Edge etaEdge = BRepBuilderAPI_MakeEdge(pnt0, pnt1);
etaWireBuilder.Add(etaEdge);
TopoDS_Wire etaLine = etaWireBuilder.Wire();

// intersection line
Handle(Geom_TrimmedCurve) profileLine = GC_MakeSegment(pnt, gp_Pnt(-1e9, 0, 0));
BRepBuilderAPI_MakeEdge ME(profileLine);
TopoDS_Shape aCrv(ME.Edge());

// now find intersection point
BRepExtrema_DistShapeShape extrema(etaLine, aCrv);
extrema.Perform();
gp_Pnt intersectionPoint = extrema.PointOnShape1(1);

// now the small line, a fraction of the original eta line
BRepBuilderAPI_MakeWire wireBuilder;
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(pnt0, intersectionPoint);
wireBuilder.Add(edge);
TopoDS_Wire fractionLine = wireBuilder.Wire();

BRepAdaptor_CompCurve aCompoundCurve1(etaLine, Standard_True);
BRepAdaptor_CompCurve aCompoundCurve2(fractionLine, Standard_True);

Standard_Real len1 = GCPnts_AbscissaPoint::Length( aCompoundCurve1 );
Standard_Real len2 = GCPnts_AbscissaPoint::Length( aCompoundCurve2 );

return (len1 / 100) * len2;
}


// Returns eta as parametric distance from a given point on the surface
double CCPACSWingSegment::GetEta(gp_Pnt pnt, bool isUpper)
{
Expand Down
18 changes: 10 additions & 8 deletions Src/CCPACSWingSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ namespace tigl {
// Returns eta as parametric distance from a given point on the surface
// Get information about a point beeing on upper/lower side with "GetIsOnTop"
double GetEta(gp_Pnt pnt, bool isUpper);

// calculates eta from a given XSI and
double GetEta(gp_Pnt pnt, double xsi);

// Returns zeta as parametric distance from a given point on the surface
// Get information about a point beeing on upper/lower side with "GetIsOnTop"
Expand Down Expand Up @@ -166,6 +169,13 @@ namespace tigl {
// Returns the upper Surface of this Segment
Handle(Geom_Surface) GetUpperSurface();

// Returns an upper or lower point on the segment surface in
// dependence of parameters eta and xsi, which range from 0.0 to 1.0.
// For eta = 0.0, xsi = 0.0 point is equal to leading edge on the
// inner wing profile. For eta = 1.0, xsi = 1.0 point is equal to the trailing
// edge on the outer wing profile. If fromUpper is true, a point
// on the upper surface is returned, otherwise from the lower.
gp_Pnt GetPoint(double eta, double xsi, bool fromUpper);

protected:
// Cleanup routine
Expand All @@ -177,14 +187,6 @@ namespace tigl {
// Builds the loft between the two segment sections
void BuildLoft(void);

// Returns an upper or lower point on the segment surface in
// dependence of parameters eta and xsi, which range from 0.0 to 1.0.
// For eta = 0.0, xsi = 0.0 point is equal to leading edge on the
// inner wing profile. For eta = 1.0, xsi = 1.0 point is equal to the trailing
// edge on the outer wing profile. If fromUpper is true, a point
// on the upper surface is returned, otherwise from the lower.
gp_Pnt GetPoint(double eta, double xsi, bool fromUpper);


private:
// Copy constructor
Expand Down
11 changes: 11 additions & 0 deletions Src/CCPACSWingSegments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ namespace tigl {
return (CCPACSWingSegment &) (*(segments[idx]));
}

// Gets a segment by uid.
CCPACSWingSegment & CCPACSWingSegments::GetSegment(const std::string& segmentUID)
{
for (CCPACSWingSegmentContainer::size_type i = 0; i < segments.size(); i++) {
if (segments[i]->GetUID() == segmentUID) {
return (CCPACSWingSegment &) (*(segments[i]));
}
}
throw CTiglError("Error: Invalid uid in CCPACSWingSegments::GetSegment", TIGL_INDEX_ERROR);
}

// Gets total segment count
int CCPACSWingSegments::GetSegmentCount(void)
{
Expand Down
3 changes: 2 additions & 1 deletion Src/CCPACSWingSegments.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ namespace tigl {
// Read CPACS segments element
void ReadCPACS(TixiDocumentHandle tixiHandle, const std::string& wingXPath);

// Gets a segment by index.
// Gets a segment by index or UID.
CCPACSWingSegment & GetSegment(const int index);
CCPACSWingSegment & GetSegment(const std::string& segmentUID);

// Gets total segment count
int GetSegmentCount(void);
Expand Down
2 changes: 0 additions & 2 deletions Src/Src.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
AdditionalIncludeDirectories="../../TIXI/Src;&quot;$(CASROOT)/inc&quot;;$(TIXI_INCLUDE)"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;WNT;IFORT_WIN32"
StringPooling="false"
MinimalRebuild="true"
BasicRuntimeChecks="3"
SmallerTypeCheck="true"
RuntimeLibrary="3"
Expand Down Expand Up @@ -188,7 +187,6 @@
AdditionalIncludeDirectories="&quot;$(TIXI_INCLUDE)&quot;;&quot;$(CASROOT)/inc&quot;;../../TIXI/Src"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;WNT;IFORT_WIN32;WIN32_DLL"
StringPooling="false"
MinimalRebuild="true"
BasicRuntimeChecks="3"
SmallerTypeCheck="true"
RuntimeLibrary="3"
Expand Down
52 changes: 52 additions & 0 deletions Src/tigl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,58 @@ DLL_EXPORT TiglReturnCode tiglWingComponentSegmentFindSegment(TiglCPACSConfigura
}



DLL_EXPORT TiglReturnCode tiglWingComponentSegmentPointGetSegmentEtaXsi(TiglCPACSConfigurationHandle cpacsHandle,
char *componentSegmentUID, double eta, double xsi,
char** wingUID, char** segmentUID,
double *segmentEta, double *segmentXsi)
{
if (segmentUID == 0) {
std::cerr << "Error: Null pointer argument for segmentUID ";
std::cerr << "in function call to tiglWingComponentSegmentPointGetSegmentEtaXsi." << std::endl;
return TIGL_NULL_POINTER;
}

if (wingUID == 0) {
std::cerr << "Error: Null pointer argument for wingUID ";
std::cerr << "in function call to tiglWingComponentSegmentPointGetSegmentEtaXsi." << std::endl;
return TIGL_NULL_POINTER;
}

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

tigl::CCPACSWing& wing = config.GetWing(1);
tigl::CCPACSWingComponentSegment& componentSegment = (tigl::CCPACSWingComponentSegment &) wing.GetComponentSegment(componentSegmentUID);

gp_Pnt pnt = componentSegment.GetPoint(eta, xsi);
*segmentXsi = xsi;

tiglWingComponentSegmentFindSegment(cpacsHandle, componentSegmentUID,
pnt.X(), pnt.Y(), pnt.Z(),
segmentUID, wingUID);

tigl::CCPACSWingSegment& segment = (tigl::CCPACSWingSegment&) wing.GetSegment(*segmentUID);
*segmentEta = segment.GetEta(pnt, xsi);

return TIGL_SUCCESS;
}
catch (std::exception& ex) {
std::cerr << ex.what() << std::endl;
return TIGL_ERROR;
}
catch (tigl::CTiglError& ex) {
std::cerr << ex.getError() << std::endl;
return ex.getCode();
}
catch (...) {
std::cerr << "Caught an exception in tiglWingComponentSegmentPointGetSegmentEtaXsi!" << std::endl;
return TIGL_ERROR;
}
}


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


Expand Down
Loading

0 comments on commit 6a56304

Please sign in to comment.