1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-21 10:13:43 +03:00

Data Exchange - Step Direction optimization #479

Refactor direction handling in STEP files for improved clarity and performance.
Moved to use array instead of vector
This commit is contained in:
Pasukhin Dmitry 2025-04-06 16:48:09 +01:00 committed by GitHub
parent a897fd5942
commit 74176f3b21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 172 additions and 116 deletions

View File

@ -40,24 +40,31 @@ void RWStepGeom_RWDirection::ReadStep(const Handle(StepData_StepReaderData)& dat
// --- own field : directionRatios --- // --- own field : directionRatios ---
Handle(TColStd_HArray1OfReal) aDirectionRatios; Standard_Real aCoordinatesItem;
Standard_Real aDirectionRatiosItem; Standard_Integer aNSub2, aNbCoord = 0;
Standard_Integer nsub2; Standard_Real aXYZ[3] = {0., 0., 0.};
if (data->ReadSubList(num, 2, "direction_ratios", ach, nsub2)) if (data->ReadSubList(num, 2, "direction_ratios", ach, aNSub2))
{ {
Standard_Integer nb2 = data->NbParams(nsub2); Standard_Integer aNbElements = data->NbParams(aNSub2);
aDirectionRatios = new TColStd_HArray1OfReal(1, nb2); if (aNbElements > 3)
for (Standard_Integer i2 = 1; i2 <= nb2; i2++)
{ {
// szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed ach->AddWarning("More than 3 direction ratios, ignored");
if (data->ReadReal(nsub2, i2, "direction_ratios", ach, aDirectionRatiosItem)) }
aDirectionRatios->SetValue(i2, aDirectionRatiosItem); aNbCoord = Min(aNbElements, 3);
for (Standard_Integer i2 = 0; i2 < aNbCoord; i2++)
{
if (data->ReadReal(aNSub2, i2 + 1, "direction_ratios", ach, aCoordinatesItem))
{
aXYZ[i2] = aCoordinatesItem;
}
} }
} }
//--- Initialisation of the read entity --- //--- Initialisation of the read entity ---
if (aNbCoord == 3)
ent->Init(aName, aDirectionRatios); ent->Init3D(aName, aXYZ[0], aXYZ[1], aXYZ[2]);
else
ent->Init2D(aName, aXYZ[0], aXYZ[1]);
} }
void RWStepGeom_RWDirection::WriteStep(StepData_StepWriter& SW, void RWStepGeom_RWDirection::WriteStep(StepData_StepWriter& SW,

View File

@ -4393,26 +4393,19 @@ static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
return; return;
aDimObj->SetPath(aSh); aDimObj->SetPath(aSh);
} }
else if (!anAP.IsNull()) else if (!anAP.IsNull() && !anAP->RefDirection().IsNull() && !anAP->Name().IsNull()
{ && !anAP->Axis().IsNull() && anAP->Name()->String().IsEqual("orientation"))
if (anAP->Name()->String().IsEqual("orientation") && !anAP->Axis().IsNull())
{ {
// for Oriented Dimensional Location // for Oriented Dimensional Location
Handle(TColStd_HArray1OfReal) aDirArr = anAP->RefDirection()->DirectionRatios(); const Handle(StepGeom_Direction)& aRefDirection = anAP->RefDirection();
gp_Dir aDir; const std::array<Standard_Real, 3>& aDirArr = aRefDirection->DirectionRatios();
Standard_Integer aDirLower = aDirArr->Lower(); if (aRefDirection->NbDirectionRatios() >= 3)
if (!aDirArr.IsNull() && aDirArr->Length() > 2)
{ {
aDir.SetCoord(aDirArr->Value(aDirLower), aDimObj->SetDirection({aDirArr[0], aDirArr[1], aDirArr[2]});
aDirArr->Value(aDirLower + 1),
aDirArr->Value(aDirLower + 2));
aDimObj->SetDirection(aDir);
} }
else if (aDirArr->Length() > 1) else if (aRefDirection->NbDirectionRatios() == 2)
{ {
aDir.SetCoord(aDirArr->Value(aDirLower), aDirArr->Value(aDirLower + 1), 0); aDimObj->SetDirection({aDirArr[0], aDirArr[1], 0.});
aDimObj->SetDirection(aDir);
}
} }
} }
} }

View File

@ -19,71 +19,71 @@ IMPLEMENT_STANDARD_RTTIEXT(StepGeom_CartesianPoint, StepGeom_Point)
StepGeom_CartesianPoint::StepGeom_CartesianPoint() {} StepGeom_CartesianPoint::StepGeom_CartesianPoint() {}
void StepGeom_CartesianPoint::Init(const Handle(TCollection_HAsciiString)& aName, void StepGeom_CartesianPoint::Init(const Handle(TCollection_HAsciiString)& theName,
const Handle(TColStd_HArray1OfReal)& aCoordinates) const Handle(TColStd_HArray1OfReal)& aCoordinates)
{ {
// --- classe own fields --- SetCoordinates(aCoordinates);
nbcoord = aCoordinates->Length();
coords[0] = aCoordinates->Value(1);
coords[1] = aCoordinates->Value(2);
coords[2] = aCoordinates->Value(3);
// coordinates = aCoordinates;
// --- classe inherited fields --- // --- classe inherited fields ---
StepRepr_RepresentationItem::Init(aName); StepRepr_RepresentationItem::Init(theName);
} }
void StepGeom_CartesianPoint::Init2D(const Handle(TCollection_HAsciiString)& aName, void StepGeom_CartesianPoint::Init2D(const Handle(TCollection_HAsciiString)& theName,
const Standard_Real X, const Standard_Real theX,
const Standard_Real Y) const Standard_Real theY)
{ {
nbcoord = 2; myNbCoord = 2;
coords[0] = X; myCoords[0] = theX;
coords[1] = Y; myCoords[1] = theY;
coords[2] = 0; myCoords[2] = 0;
// --- classe inherited fields --- // --- classe inherited fields ---
StepRepr_RepresentationItem::Init(aName); StepRepr_RepresentationItem::Init(theName);
} }
void StepGeom_CartesianPoint::Init3D(const Handle(TCollection_HAsciiString)& aName, void StepGeom_CartesianPoint::Init3D(const Handle(TCollection_HAsciiString)& theName,
const Standard_Real X, const Standard_Real theX,
const Standard_Real Y, const Standard_Real theY,
const Standard_Real Z) const Standard_Real theZ)
{ {
nbcoord = 3; myNbCoord = 3;
coords[0] = X; myCoords[0] = theX;
coords[1] = Y; myCoords[1] = theY;
coords[2] = Z; myCoords[2] = theZ;
// --- classe inherited fields --- // --- classe inherited fields ---
StepRepr_RepresentationItem::Init(aName); StepRepr_RepresentationItem::Init(theName);
} }
void StepGeom_CartesianPoint::SetCoordinates(const Handle(TColStd_HArray1OfReal)& aCoordinates) void StepGeom_CartesianPoint::SetCoordinates(const Handle(TColStd_HArray1OfReal)& aCoordinates)
{ {
nbcoord = aCoordinates->Length(); myNbCoord = aCoordinates->Length();
coords[0] = aCoordinates->Value(1); if (myNbCoord > 0)
coords[1] = aCoordinates->Value(2); myCoords[0] = aCoordinates->Value(1);
coords[2] = aCoordinates->Value(3); if (myNbCoord > 1)
// coordinates = aCoordinates; myCoords[1] = aCoordinates->Value(2);
if (myNbCoord > 2)
myCoords[2] = aCoordinates->Value(3);
} }
void StepGeom_CartesianPoint::SetCoordinates(const std::array<Standard_Real, 3>& theCoordinates) void StepGeom_CartesianPoint::SetCoordinates(const std::array<Standard_Real, 3>& theCoordinates)
{ {
coords = theCoordinates; myCoords = theCoordinates;
} }
const std::array<Standard_Real, 3>& StepGeom_CartesianPoint::Coordinates() const const std::array<Standard_Real, 3>& StepGeom_CartesianPoint::Coordinates() const
{ {
return coords; return myCoords;
} }
Standard_Real StepGeom_CartesianPoint::CoordinatesValue(const Standard_Integer num) const Standard_Real StepGeom_CartesianPoint::CoordinatesValue(const Standard_Integer num) const
{ {
return coords[num - 1]; return myCoords[num - 1];
// return coordinates->Value(num); }
void StepGeom_CartesianPoint::SetNbCoordinates(const Standard_Integer num)
{
myNbCoord = num;
} }
Standard_Integer StepGeom_CartesianPoint::NbCoordinates() const Standard_Integer StepGeom_CartesianPoint::NbCoordinates() const
{ {
return nbcoord; return myNbCoord;
// return coordinates->Length();
} }

View File

@ -38,34 +38,35 @@ public:
//! Returns a CartesianPoint //! Returns a CartesianPoint
Standard_EXPORT StepGeom_CartesianPoint(); Standard_EXPORT StepGeom_CartesianPoint();
Standard_EXPORT void Init(const Handle(TCollection_HAsciiString)& aName, Standard_EXPORT void Init(const Handle(TCollection_HAsciiString)& theName,
const Handle(TColStd_HArray1OfReal)& aCoordinates); const Handle(TColStd_HArray1OfReal)& theCoordinates);
Standard_EXPORT void Init2D(const Handle(TCollection_HAsciiString)& aName, Standard_EXPORT void Init2D(const Handle(TCollection_HAsciiString)& theName,
const Standard_Real X, const Standard_Real theX,
const Standard_Real Y); const Standard_Real theY);
Standard_EXPORT void Init3D(const Handle(TCollection_HAsciiString)& aName, Standard_EXPORT void Init3D(const Handle(TCollection_HAsciiString)& theName,
const Standard_Real X, const Standard_Real theX,
const Standard_Real Y, const Standard_Real theY,
const Standard_Real Z); const Standard_Real theZ);
Standard_EXPORT void SetCoordinates(const Handle(TColStd_HArray1OfReal)& aCoordinates); Standard_EXPORT void SetCoordinates(const Handle(TColStd_HArray1OfReal)& theCoordinates);
Standard_EXPORT void SetCoordinates(const std::array<Standard_Real, 3>& theCoordinates); Standard_EXPORT void SetCoordinates(const std::array<Standard_Real, 3>& theCoordinates);
Standard_EXPORT const std::array<Standard_Real, 3>& Coordinates() const; Standard_EXPORT const std::array<Standard_Real, 3>& Coordinates() const;
Standard_EXPORT Standard_Real CoordinatesValue(const Standard_Integer num) const; Standard_EXPORT Standard_Real CoordinatesValue(const Standard_Integer theInd) const;
Standard_EXPORT void SetNbCoordinates(const Standard_Integer theSize);
Standard_EXPORT Standard_Integer NbCoordinates() const; Standard_EXPORT Standard_Integer NbCoordinates() const;
DEFINE_STANDARD_RTTIEXT(StepGeom_CartesianPoint, StepGeom_Point) DEFINE_STANDARD_RTTIEXT(StepGeom_CartesianPoint, StepGeom_Point)
protected:
private: private:
Standard_Integer nbcoord; Standard_Integer myNbCoord;
std::array<Standard_Real, 3> coords; std::array<Standard_Real, 3> myCoords;
}; };
#endif // _StepGeom_CartesianPoint_HeaderFile #endif // _StepGeom_CartesianPoint_HeaderFile

View File

@ -18,31 +18,74 @@ IMPLEMENT_STANDARD_RTTIEXT(StepGeom_Direction, StepGeom_GeometricRepresentationI
StepGeom_Direction::StepGeom_Direction() {} StepGeom_Direction::StepGeom_Direction() {}
void StepGeom_Direction::Init(const Handle(TCollection_HAsciiString)& aName, void StepGeom_Direction::Init(const Handle(TCollection_HAsciiString)& theName,
const Handle(TColStd_HArray1OfReal)& aDirectionRatios) const Handle(TColStd_HArray1OfReal)& theDirectionRatios)
{ {
// --- classe own fields --- // --- classe own fields ---
directionRatios = aDirectionRatios; SetDirectionRatios(theDirectionRatios);
// --- classe inherited fields --- // --- classe inherited fields ---
StepRepr_RepresentationItem::Init(aName); StepRepr_RepresentationItem::Init(theName);
} }
void StepGeom_Direction::SetDirectionRatios(const Handle(TColStd_HArray1OfReal)& aDirectionRatios) void StepGeom_Direction::Init3D(const Handle(TCollection_HAsciiString)& theName,
const Standard_Real theDirectionRatios1,
const Standard_Real theDirectionRatios2,
const Standard_Real theDirectionRatios3)
{ {
directionRatios = aDirectionRatios; myNbCoord = 3;
myCoords[0] = theDirectionRatios1;
myCoords[1] = theDirectionRatios2;
myCoords[2] = theDirectionRatios3;
// --- classe inherited fields ---
StepRepr_RepresentationItem::Init(theName);
} }
Handle(TColStd_HArray1OfReal) StepGeom_Direction::DirectionRatios() const void StepGeom_Direction::Init2D(const Handle(TCollection_HAsciiString)& theName,
const Standard_Real theDirectionRatios1,
const Standard_Real theDirectionRatios2)
{ {
return directionRatios; myNbCoord = 2;
myCoords[0] = theDirectionRatios1;
myCoords[1] = theDirectionRatios2;
myCoords[2] = 0.0;
// --- classe inherited fields ---
StepRepr_RepresentationItem::Init(theName);
} }
Standard_Real StepGeom_Direction::DirectionRatiosValue(const Standard_Integer num) const void StepGeom_Direction::SetDirectionRatios(const Handle(TColStd_HArray1OfReal)& theDirectionRatios)
{ {
return directionRatios->Value(num); myNbCoord = theDirectionRatios->Length();
if (myNbCoord > 0)
myCoords[0] = theDirectionRatios->Value(1);
if (myNbCoord > 1)
myCoords[1] = theDirectionRatios->Value(2);
if (myNbCoord > 2)
myCoords[2] = theDirectionRatios->Value(3);
}
void StepGeom_Direction::SetDirectionRatios(const std::array<Standard_Real, 3>& theDirectionRatios)
{
myCoords[0] = theDirectionRatios[0];
myCoords[1] = theDirectionRatios[1];
myCoords[2] = theDirectionRatios[2];
}
const std::array<Standard_Real, 3>& StepGeom_Direction::DirectionRatios() const
{
return myCoords;
}
Standard_Real StepGeom_Direction::DirectionRatiosValue(const Standard_Integer theInd) const
{
return myCoords[theInd - 1];
}
void StepGeom_Direction::SetNbDirectionRatios(const Standard_Integer theSize)
{
myNbCoord = theSize;
} }
Standard_Integer StepGeom_Direction::NbDirectionRatios() const Standard_Integer StepGeom_Direction::NbDirectionRatios() const
{ {
return directionRatios->Length(); return myNbCoord;
} }

View File

@ -24,6 +24,9 @@
#include <StepGeom_GeometricRepresentationItem.hxx> #include <StepGeom_GeometricRepresentationItem.hxx>
#include <Standard_Real.hxx> #include <Standard_Real.hxx>
#include <Standard_Integer.hxx> #include <Standard_Integer.hxx>
#include <array>
class TCollection_HAsciiString; class TCollection_HAsciiString;
class StepGeom_Direction; class StepGeom_Direction;
@ -36,22 +39,35 @@ public:
//! Returns a Direction //! Returns a Direction
Standard_EXPORT StepGeom_Direction(); Standard_EXPORT StepGeom_Direction();
Standard_EXPORT void Init(const Handle(TCollection_HAsciiString)& aName, Standard_EXPORT void Init(const Handle(TCollection_HAsciiString)& theName,
const Handle(TColStd_HArray1OfReal)& aDirectionRatios); const Handle(TColStd_HArray1OfReal)& theDirectionRatios);
Standard_EXPORT void SetDirectionRatios(const Handle(TColStd_HArray1OfReal)& aDirectionRatios); Standard_EXPORT void Init3D(const Handle(TCollection_HAsciiString)& theName,
const Standard_Real theDirectionRatios1,
const Standard_Real theDirectionRatios2,
const Standard_Real theDirectionRatios3);
Standard_EXPORT Handle(TColStd_HArray1OfReal) DirectionRatios() const; Standard_EXPORT void Init2D(const Handle(TCollection_HAsciiString)& theName,
const Standard_Real theDirectionRatios1,
const Standard_Real theDirectionRatios2);
Standard_EXPORT Standard_Real DirectionRatiosValue(const Standard_Integer num) const; Standard_EXPORT void SetDirectionRatios(const Handle(TColStd_HArray1OfReal)& theDirectionRatios);
Standard_EXPORT void SetDirectionRatios(const std::array<Standard_Real, 3>& theDirectionRatios);
Standard_EXPORT const std::array<Standard_Real, 3>& DirectionRatios() const;
Standard_EXPORT Standard_Real DirectionRatiosValue(const Standard_Integer theInd) const;
Standard_EXPORT void SetNbDirectionRatios(const Standard_Integer theSize);
Standard_EXPORT Standard_Integer NbDirectionRatios() const; Standard_EXPORT Standard_Integer NbDirectionRatios() const;
DEFINE_STANDARD_RTTIEXT(StepGeom_Direction, StepGeom_GeometricRepresentationItem) DEFINE_STANDARD_RTTIEXT(StepGeom_Direction, StepGeom_GeometricRepresentationItem)
protected:
private: private:
Handle(TColStd_HArray1OfReal) directionRatios; Standard_Integer myNbCoord;
std::array<Standard_Real, 3> myCoords;
}; };
#endif // _StepGeom_Direction_HeaderFile #endif // _StepGeom_Direction_HeaderFile

View File

@ -24,21 +24,17 @@ struct StepTidy_DirectionHasher
// Hashes the direction by its name and direction ratios. // Hashes the direction by its name and direction ratios.
std::size_t operator()(const Handle(StepGeom_Direction)& theDirection) const noexcept std::size_t operator()(const Handle(StepGeom_Direction)& theDirection) const noexcept
{ {
// Prepare an array of direction ratios. const std::array<Standard_Real, 3>& aCoords = theDirection->DirectionRatios();
const Handle(TColStd_HArray1OfReal) aCoords = theDirection->DirectionRatios(); // If Cartesian point has no name, hash only directional ratios.
int anArray[3]{};
for (int anIndex = aCoords->Lower(); anIndex < aCoords->Upper(); ++anIndex)
{
anArray[anIndex] = static_cast<int>(aCoords->Value(anIndex));
}
// If direction has no name, hash only direction ratios.
if (theDirection->Name().IsNull()) if (theDirection->Name().IsNull())
{ {
return opencascade::hashBytes(anArray, sizeof(anArray)); return opencascade::hashBytes(aCoords.data(), static_cast<int>(aCoords.size()));
} }
// Otherwise, hash both direction ratios and name. // Otherwise, hash both coordinates and name.
const size_t aHashes[2]{opencascade::hashBytes(anArray, sizeof(anArray)), const size_t aHashes[2]{
opencascade::hashBytes(aCoords.data(), static_cast<int>(aCoords.size())),
std::hash<TCollection_AsciiString>{}(theDirection->Name()->String())}; std::hash<TCollection_AsciiString>{}(theDirection->Name()->String())};
return opencascade::hashBytes(aHashes, sizeof(aHashes)); return opencascade::hashBytes(aHashes, sizeof(aHashes));
} }
@ -58,15 +54,15 @@ struct StepTidy_DirectionHasher
// Compare coordinates. // Compare coordinates.
constexpr double aTolerance = 1e-12; constexpr double aTolerance = 1e-12;
const Handle(TColStd_HArray1OfReal) aCoords1 = theDirection1->DirectionRatios(); const std::array<Standard_Real, 3>& aCoords1 = theDirection1->DirectionRatios();
const Handle(TColStd_HArray1OfReal) aCoords2 = theDirection2->DirectionRatios(); const std::array<Standard_Real, 3>& aCoords2 = theDirection2->DirectionRatios();
if (aCoords1->Length() != aCoords2->Length()) if (theDirection1->NbDirectionRatios() != theDirection2->NbDirectionRatios())
{ {
return false; return false;
} }
for (Standard_Integer i = aCoords1->Lower(); i <= aCoords1->Upper(); ++i) for (int anIndex = 0; anIndex < theDirection1->NbDirectionRatios(); ++anIndex)
{ {
if (std::abs(aCoords1->Value(i) - aCoords2->Value(i)) > aTolerance) if (std::abs(aCoords1[anIndex] - aCoords2[anIndex]) > aTolerance)
{ {
return false; return false;
} }

View File

@ -2510,7 +2510,7 @@ Handle(TColStd_HArray1OfReal) StepToGeom::MakeYprRotation(
} }
if (SR.RotationAboutDirection().IsNull() if (SR.RotationAboutDirection().IsNull()
|| SR.RotationAboutDirection()->DirectionOfAxis()->DirectionRatios()->Length() != 3 || SR.RotationAboutDirection()->DirectionOfAxis()->NbDirectionRatios() != 3
|| theCntxt.IsNull()) || theCntxt.IsNull())
{ {
return NULL; return NULL;