Loading files
3d097a032This file is pinned to the selected release. Download the original to open it in your design tool.
// Copyright (c) 2025 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _GeomHash_BSplineSurfaceHasher_HeaderFile
#define _GeomHash_BSplineSurfaceHasher_HeaderFile
#include <Standard_HashUtils.hxx>
#include <Geom_BSplineSurface.hxx>
#include <GeomHash_PointHasher.pxx>
#include <cmath>
#include <Precision.hxx>
//! OCCT-style hasher for Geom_BSplineSurface.
//! Used for geometry deduplication.
//! Hashes only metadata (degrees, pole counts, knot counts, rationality) for efficiency.
struct GeomHash_BSplineSurfaceHasher
{
double CompTolerance;
double HashTolerance;
GeomHash_BSplineSurfaceHasher(double theCompTolerance = Precision::Angular(),
double theHashTolerance = Precision::Confusion())
: CompTolerance(theCompTolerance),
HashTolerance(theHashTolerance)
{
}
// Hashes the B-spline surface metadata only.
std::size_t operator()(const occ::handle<Geom_BSplineSurface>& theSurface) const noexcept
{
const std::size_t aHashes[7] = {
opencascade::hash(theSurface->UDegree()),
opencascade::hash(theSurface->VDegree()),
opencascade::hash(theSurface->NbUPoles()),
opencascade::hash(theSurface->NbVPoles()),
opencascade::hash(theSurface->NbUKnots()),
opencascade::hash(theSurface->NbVKnots()),
opencascade::hash(static_cast<int>(theSurface->IsURational())
| (static_cast<int>(theSurface->IsVRational()) << 1))};
return opencascade::hashBytes(aHashes, sizeof(aHashes));
}
// Compares two B-spline surfaces by full geometric data.
bool operator()(const occ::handle<Geom_BSplineSurface>& theSurface1,
const occ::handle<Geom_BSplineSurface>& theSurface2) const noexcept
{
// Compare degrees
if (theSurface1->UDegree() != theSurface2->UDegree()
|| theSurface1->VDegree() != theSurface2->VDegree())
{
return false;
}
// Compare knot counts
if (theSurface1->NbUKnots() != theSurface2->NbUKnots()
|| theSurface1->NbVKnots() != theSurface2->NbVKnots())
{
return false;
}
// Compare U knots and multiplicities
for (int i = 1; i <= theSurface1->NbUKnots(); ++i)
{
if (std::abs(theSurface1->UKnot(i) - theSurface2->UKnot(i)) > CompTolerance
|| theSurface1->UMultiplicity(i) != theSurface2->UMultiplicity(i))
{
return false;
}
}
// Compare V knots and multiplicities
for (int i = 1; i <= theSurface1->NbVKnots(); ++i)
{
if (std::abs(theSurface1->VKnot(i) - theSurface2->VKnot(i)) > CompTolerance
|| theSurface1->VMultiplicity(i) != theSurface2->VMultiplicity(i))
{
return false;
}
}
// Compare rationality
if (theSurface1->IsURational() != theSurface2->IsURational()
|| theSurface1->IsVRational() != theSurface2->IsVRational())
{
return false;
}
const GeomHash_PointHasher aPointHasher(CompTolerance, HashTolerance);
// Compare poles
for (int i = 1; i <= theSurface1->NbUPoles(); ++i)
{
for (int j = 1; j <= theSurface1->NbVPoles(); ++j)
{
if (!aPointHasher(theSurface1->Pole(i, j), theSurface2->Pole(i, j)))
{
return false;
}
}
}
// Compare weights if rational
if (theSurface1->IsURational() || theSurface1->IsVRational())
{
for (int i = 1; i <= theSurface1->NbUPoles(); ++i)
{
for (int j = 1; j <= theSurface1->NbVPoles(); ++j)
{
if (std::abs(theSurface1->Weight(i, j) - theSurface2->Weight(i, j)) > CompTolerance)
{
return false;
}
}
}
}
return true;
}
};
#endif // _GeomHash_BSplineSurfaceHasher_HeaderFile