Skip to content

Commit

Permalink
Bug fix : extra triangle in getTriangleCountOfAllPatches
Browse files Browse the repository at this point in the history
Improve const correcteness in src\resqml2_0_1\TriangulatedSetRepresentation.cpp
Much more unit tests for TriangulatedSetRepresentation
Explicitely state that FESAPI requires C++17 in README
  • Loading branch information
philippeVerney committed Jan 21, 2025
1 parent f2099a5 commit e7050c7
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- build
- fesapi (Git clone this repository into this folder "fesapi". You should then have a path fesapiEnv/fesapi/src)
- dependencies
- The following compilers are known to work
- The following compilers (C++17 is needed) are known to work
- gcc from version 8
- visual studio from version 2019
- clang from version 5.0
Expand Down
44 changes: 17 additions & 27 deletions src/resqml2_0_1/TriangulatedSetRepresentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ TriangulatedSetRepresentation::TriangulatedSetRepresentation(RESQML2_NS::Abstrac

COMMON_NS::DataObjectReference TriangulatedSetRepresentation::getHdfProxyDor() const
{
resqml20__TrianglePatch* patch = static_cast<_resqml20__TriangulatedSetRepresentation*>(gsoapProxy2_0_1)->TrianglePatch[0];
resqml20__TrianglePatch const* patch = static_cast<_resqml20__TriangulatedSetRepresentation const*>(gsoapProxy2_0_1)->TrianglePatch[0];
if (patch->Triangles->soap_type() == SOAP_TYPE_gsoap_resqml2_0_1_resqml20__IntegerHdf5Array)
{
return COMMON_NS::DataObjectReference(static_cast<resqml20__IntegerHdf5Array*>(patch->Triangles)->Values->HdfProxy);
return COMMON_NS::DataObjectReference(static_cast<resqml20__IntegerHdf5Array const*>(patch->Triangles)->Values->HdfProxy);
}

return getHdfProxyDorFromPointGeometryPatch(getPointGeometry2_0_1(0));
}

resqml20__PointGeometry* TriangulatedSetRepresentation::getPointGeometry2_0_1(uint64_t patchIndex) const
{
return static_cast<_resqml20__TriangulatedSetRepresentation*>(gsoapProxy2_0_1)->TrianglePatch.at(patchIndex)->Geometry;
return static_cast<_resqml20__TriangulatedSetRepresentation const*>(gsoapProxy2_0_1)->TrianglePatch.at(patchIndex)->Geometry;
}

void TriangulatedSetRepresentation::pushBackTrianglePatch(
Expand All @@ -101,7 +101,7 @@ void TriangulatedSetRepresentation::pushBackTrianglePatch(
patch->PatchIndex = triRep->TrianglePatch.size();
triRep->TrianglePatch.push_back(patch);

uint64_t pointCountDims[2] = { nodeCount, 3 };
const uint64_t pointCountDims[2] = { nodeCount, 3 };
patch->NodeCount = nodeCount;
patch->Geometry = createPointGeometryPatch2_0_1(patch->PatchIndex, nodes, localCrs, pointCountDims, 2, proxy);
getRepository()->addRelationship(this, localCrs);
Expand All @@ -118,7 +118,7 @@ void TriangulatedSetRepresentation::pushBackTrianglePatch(
ossForHdf << "triangles_patch" << patch->PatchIndex;
hdfTriangles->Values->PathInHdfFile = getHdfGroup() + "/" + ossForHdf.str();
// ************ HDF *************
uint64_t dim[2] = {triangleCount, 3};
const uint64_t dim[2] = {triangleCount, 3};
proxy->writeArrayNd(getHdfGroup(),
ossForHdf.str(), COMMON_NS::AbstractObject::numericalDatatypeEnum::UINT32,
triangleNodeIndices,
Expand All @@ -127,19 +127,16 @@ void TriangulatedSetRepresentation::pushBackTrianglePatch(

uint64_t TriangulatedSetRepresentation::getXyzPointCountOfPatch(unsigned int patchIndex) const
{
return static_cast<_resqml20__TriangulatedSetRepresentation*>(gsoapProxy2_0_1)->TrianglePatch.at(patchIndex)->NodeCount;
return static_cast<_resqml20__TriangulatedSetRepresentation const*>(gsoapProxy2_0_1)->TrianglePatch.at(patchIndex)->NodeCount;
}

void TriangulatedSetRepresentation::getXyzPointsOfPatch(unsigned int patchIndex, double* xyzPoints) const
{
if (patchIndex >= getPatchCount())
throw range_error("The index of the patch is not in the allowed range of patch.");

resqml20__PointGeometry* pointGeom = getPointGeometry2_0_1(patchIndex);
resqml20__PointGeometry const* pointGeom = getPointGeometry2_0_1(patchIndex);
if (pointGeom != nullptr && pointGeom->Points->soap_type() == SOAP_TYPE_gsoap_resqml2_0_1_resqml20__Point3dHdf5Array)
{
eml20__Hdf5Dataset const * dataset = static_cast<resqml20__Point3dHdf5Array*>(pointGeom->Points)->Coordinates;
EML2_NS::AbstractHdfProxy * hdfProxy = getHdfProxyFromDataset(dataset);
eml20__Hdf5Dataset const* dataset = static_cast<resqml20__Point3dHdf5Array const*>(pointGeom->Points)->Coordinates;
EML2_NS::AbstractHdfProxy* hdfProxy = getHdfProxyFromDataset(dataset);
hdfProxy->readArrayNdOfDoubleValues(dataset->PathInHdfFile, xyzPoints);
}
else
Expand All @@ -148,36 +145,29 @@ void TriangulatedSetRepresentation::getXyzPointsOfPatch(unsigned int patchIndex,

uint64_t TriangulatedSetRepresentation::getTriangleCountOfPatch(unsigned int patchIndex) const
{
return static_cast<_resqml20__TriangulatedSetRepresentation*>(gsoapProxy2_0_1)->TrianglePatch.at(patchIndex)->Count;
return static_cast<_resqml20__TriangulatedSetRepresentation const*>(gsoapProxy2_0_1)->TrianglePatch.at(patchIndex)->Count;
}

uint64_t TriangulatedSetRepresentation::getTriangleCountOfAllPatches() const
{
return std::accumulate(
static_cast<_resqml20__TriangulatedSetRepresentation*>(gsoapProxy2_0_1)->TrianglePatch.begin(),
static_cast<_resqml20__TriangulatedSetRepresentation*>(gsoapProxy2_0_1)->TrianglePatch.end(),
1,
[](int a, resqml20__TrianglePatch const* b) {
static_cast<_resqml20__TriangulatedSetRepresentation const*>(gsoapProxy2_0_1)->TrianglePatch.begin(),
static_cast<_resqml20__TriangulatedSetRepresentation const*>(gsoapProxy2_0_1)->TrianglePatch.end(),
0,
[](uint64_t a, resqml20__TrianglePatch const* b) {
return a + b->Count;
}
);
}

void TriangulatedSetRepresentation::getTriangleNodeIndicesOfPatch(unsigned int patchIndex, unsigned int* triangleNodeIndices) const
{
_resqml20__TriangulatedSetRepresentation* triRep = static_cast<_resqml20__TriangulatedSetRepresentation*>(gsoapProxy2_0_1);

if (patchIndex >= triRep->TrianglePatch.size()) {
throw out_of_range("The patchIndex is out of range");
}

readArrayNdOfUInt32Values(triRep->TrianglePatch[patchIndex]->Triangles, triangleNodeIndices);
readArrayNdOfUInt32Values(static_cast<_resqml20__TriangulatedSetRepresentation const*>(gsoapProxy2_0_1)->TrianglePatch.at(patchIndex)->Triangles, triangleNodeIndices);
}

void TriangulatedSetRepresentation::getTriangleNodeIndicesOfAllPatches(unsigned int* triangleNodeIndices) const
{
_resqml20__TriangulatedSetRepresentation* triRep = static_cast<_resqml20__TriangulatedSetRepresentation*>(gsoapProxy2_0_1);
size_t patchCount = triRep->TrianglePatch.size();
const size_t patchCount = static_cast<_resqml20__TriangulatedSetRepresentation const*>(gsoapProxy2_0_1)->TrianglePatch.size();
for (size_t patchIndex = 0; patchIndex < patchCount; patchIndex++)
{
getTriangleNodeIndicesOfPatch(patchIndex, triangleNodeIndices);
Expand All @@ -187,5 +177,5 @@ void TriangulatedSetRepresentation::getTriangleNodeIndicesOfAllPatches(unsigned

uint64_t TriangulatedSetRepresentation::getPatchCount() const
{
return static_cast<_resqml20__TriangulatedSetRepresentation*>(gsoapProxy2_0_1)->TrianglePatch.size();
return static_cast<_resqml20__TriangulatedSetRepresentation const*>(gsoapProxy2_0_1)->TrianglePatch.size();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,54 @@ void FaultMultiPatchTriangulatedSetRepresentationTest::initRepo()
TriangulatedSetRepresentation* rep = repo->createTriangulatedSetRepresentation(interp, defaultUuid, defaultTitle);
REQUIRE( rep != nullptr );

// Patch 0
double explicitPointsFault1Patch0[18] = {150, 0, 200, 150, 100, 200, 150, 200, 200,
250, 0, 300, 250, 100, 300, 250, 200, 300};
unsigned int triangleNodeIndexFaultPatch0[12] = {0,4,3, 0,1,4, 1,2,4, 2,5,4};
rep->pushBackTrianglePatch(6, explicitPointsFault1Patch0, 4, triangleNodeIndexFaultPatch0, repo->getHdfProxySet()[0]);
// Patch 1
double explicitPointsFault1Patch1[18] = {250, 0, 300, 250, 100, 300, 250, 200, 300,
300, 0, 350, 300, 100, 350, 300, 200, 350};
unsigned int triangleNodeIndexFaultPatch1[12] = {6,10,9, 6,7,10, 7,8,10, 8,11,10};
rep->pushBackTrianglePatch(6, explicitPointsFault1Patch1, 4, triangleNodeIndexFaultPatch1, repo->getHdfProxySet()[0]);
// Patch 2
double explicitPointsFault1Patch2[18] = {300, 0, 350, 300, 100, 350, 300, 200, 350,
450, 0, 500, 450, 100, 500, 450, 200, 500};
unsigned int triangleNodeIndexFaultPatch2[12] = {12,16,15, 12,13,16, 13,14,16, 14,17,16};
rep->pushBackTrianglePatch(6, explicitPointsFault1Patch2, 4, triangleNodeIndexFaultPatch2, repo->getHdfProxySet()[0]);
// Patch 3
double explicitPointsFault1Patch3[18] = {450, 0, 500, 450, 100, 500, 450, 200, 500,
500, 0, 550, 500, 100, 550 ,500, 200, 550};
unsigned int triangleNodeIndexFaultPatch3[12] = {18,22,21, 18,19,22, 19,20,22, 20,23,22};
rep->pushBackTrianglePatch(6, explicitPointsFault1Patch3, 4, triangleNodeIndexFaultPatch3, repo->getHdfProxySet()[0]);
// Patch 4
double explicitPointsFault1Patch4[18] = {500, 0, 550, 500, 100, 550 ,500, 200, 550,
600, 0, 650, 600, 100, 650, 600, 200, 650};
unsigned int triangleNodeIndexFaultPatch4[12] = {24,28,27, 24,25,28, 25,26,28, 26,29,28};
rep->pushBackTrianglePatch(6, explicitPointsFault1Patch4, 4, triangleNodeIndexFaultPatch4, repo->getHdfProxySet()[0]);
}

void FaultMultiPatchTriangulatedSetRepresentationTest::readRepo()
{
RESQML2_NS::TriangulatedSetRepresentation* rep = repo->getDataObjectByUuid<RESQML2_NS::TriangulatedSetRepresentation>(defaultUuid);
REQUIRE(rep->getSeismicSupportOfPatch(0) == nullptr);
REQUIRE(rep->getPatchCount() == 5);
REQUIRE(rep->getRepresentationSetRepresentationCount() == 0);
REQUIRE(rep->getPropertySet().empty());
REQUIRE(rep->getPointsPropertyCount() == 0);
REQUIRE(rep->getSubRepresentationCount() == 0);
REQUIRE(rep->getValuesPropertyCount() == 0);
REQUIRE(rep->getTimeSeries() == nullptr);
REQUIRE(rep->getTitle() == defaultTitle);
REQUIRE(rep->getUuid() == defaultUuid);
for (size_t patchIdx = 0; patchIdx < 5; ++patchIdx) {
REQUIRE(rep->getTriangleCountOfPatch(patchIdx) == 4);
REQUIRE(rep->getXyzPointCountOfPatch(0) == 6);
}
REQUIRE(rep->getTriangleCountOfAllPatches() == 20);
REQUIRE(rep->getXyzPointCountOfAllPatches() == 30);

uint32_t triangleNodeIndexFaultPatch[12];
rep->getTriangleNodeIndicesOfPatch(0, triangleNodeIndexFaultPatch);
REQUIRE(std::equal(begin(triangleNodeIndexFaultPatch0), end(triangleNodeIndexFaultPatch0), begin(triangleNodeIndexFaultPatch)));
rep->getTriangleNodeIndicesOfPatch(1, triangleNodeIndexFaultPatch);
REQUIRE(std::equal(begin(triangleNodeIndexFaultPatch1), end(triangleNodeIndexFaultPatch1), begin(triangleNodeIndexFaultPatch)));
rep->getTriangleNodeIndicesOfPatch(2, triangleNodeIndexFaultPatch);
REQUIRE(std::equal(begin(triangleNodeIndexFaultPatch2), end(triangleNodeIndexFaultPatch2), begin(triangleNodeIndexFaultPatch)));
rep->getTriangleNodeIndicesOfPatch(3, triangleNodeIndexFaultPatch);
REQUIRE(std::equal(begin(triangleNodeIndexFaultPatch3), end(triangleNodeIndexFaultPatch3), begin(triangleNodeIndexFaultPatch)));
rep->getTriangleNodeIndicesOfPatch(4, triangleNodeIndexFaultPatch);
REQUIRE(std::equal(begin(triangleNodeIndexFaultPatch4), end(triangleNodeIndexFaultPatch4), begin(triangleNodeIndexFaultPatch)));

double explicitPointsFault[18];
rep->getXyzPointsOfPatch(0, explicitPointsFault);
REQUIRE(std::equal(begin(explicitPointsFault1Patch0), end(explicitPointsFault1Patch0), begin(explicitPointsFault)));
rep->getXyzPointsOfPatch(1, explicitPointsFault);
REQUIRE(std::equal(begin(explicitPointsFault1Patch1), end(explicitPointsFault1Patch1), begin(explicitPointsFault)));
rep->getXyzPointsOfPatch(2, explicitPointsFault);
REQUIRE(std::equal(begin(explicitPointsFault1Patch2), end(explicitPointsFault1Patch2), begin(explicitPointsFault)));
rep->getXyzPointsOfPatch(3, explicitPointsFault);
REQUIRE(std::equal(begin(explicitPointsFault1Patch3), end(explicitPointsFault1Patch3), begin(explicitPointsFault)));
rep->getXyzPointsOfPatch(4, explicitPointsFault);
REQUIRE(std::equal(begin(explicitPointsFault1Patch4), end(explicitPointsFault1Patch4), begin(explicitPointsFault)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,27 @@ namespace resqml2_test {
protected:
void initRepo();
void readRepo();

private:
// Patch 0
static constexpr double explicitPointsFault1Patch0[18] = { 150, 0, 200, 150, 100, 200, 150, 200, 200,
250, 0, 300, 250, 100, 300, 250, 200, 300 };
static constexpr uint32_t triangleNodeIndexFaultPatch0[12] = { 0,4,3, 0,1,4, 1,2,4, 2,5,4 };
// Patch 1
static constexpr double explicitPointsFault1Patch1[18] = { 250, 0, 300, 250, 100, 300, 250, 200, 300,
300, 0, 350, 300, 100, 350, 300, 200, 350 };
static constexpr uint32_t triangleNodeIndexFaultPatch1[12] = { 6,10,9, 6,7,10, 7,8,10, 8,11,10 };
// Patch 2
static constexpr double explicitPointsFault1Patch2[18] = { 300, 0, 350, 300, 100, 350, 300, 200, 350,
450, 0, 500, 450, 100, 500, 450, 200, 500 };
static constexpr uint32_t triangleNodeIndexFaultPatch2[12] = { 12,16,15, 12,13,16, 13,14,16, 14,17,16 };
// Patch 3
static constexpr double explicitPointsFault1Patch3[18] = { 450, 0, 500, 450, 100, 500, 450, 200, 500,
500, 0, 550, 500, 100, 550 ,500, 200, 550 };
static constexpr uint32_t triangleNodeIndexFaultPatch3[12] = { 18,22,21, 18,19,22, 19,20,22, 20,23,22 };
// Patch 4
static constexpr double explicitPointsFault1Patch4[18] = { 500, 0, 550, 500, 100, 550 ,500, 200, 550,
600, 0, 650, 600, 100, 650, 600, 200, 650 };
static constexpr uint32_t triangleNodeIndexFaultPatch4[12] = { 24,28,27, 24,25,28, 25,26,28, 26,29,28 };
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,42 @@ FaultSinglePatchTriangulatedSetRepresentationTest::FaultSinglePatchTriangulatedS

void FaultSinglePatchTriangulatedSetRepresentationTest::initRepo()
{
FaultInterpretation * interp = repo->getDataObjectByUuid<FaultInterpretation>(FaultInterpretationTest::defaultUuid);
FaultInterpretation* interp = repo->getDataObjectByUuid<FaultInterpretation>(FaultInterpretationTest::defaultUuid);
if (interp == nullptr) {
interp = repo->createPartial<RESQML2_0_1_NS::FaultInterpretation>(FaultInterpretationTest::defaultUuid, "");
}

TriangulatedSetRepresentation* rep = repo->createTriangulatedSetRepresentation(interp, defaultUuid, defaultTitle);
REQUIRE( rep != nullptr );

double nodesFaultSinglePatchTriangulatedSetRepresentation[] = {
150, 0, 200,
150, 100, 200,
150, 200, 200,
250, 0, 300,
250, 100, 300,
250, 200, 300,
300, 0, 350,
300, 100, 350,
300, 200, 350,
450, 0, 500,
450, 100, 500,
450, 200, 500,
500, 0, 550,
500, 100, 550,
500, 200, 550,
600, 0, 650,
600, 100, 650,
600, 200, 650 };
unsigned int triangleNodeIndexFault[60] = {0,4,3, 0,1,4, 1,2,4, 2,5,4,
3,7,6, 3,4,7, 4,5,7, 5,8,7,
6,10,9, 6,7,10, 7,8,10, 8,11,10,
9,13,12, 9,10,13, 10,11,13, 11,14,13,
12,16,15, 12,13,16, 13,14,16, 14,17,16 };
rep->pushBackTrianglePatch(18, nodesFaultSinglePatchTriangulatedSetRepresentation, 20, triangleNodeIndexFault, repo->getHdfProxySet()[0]);
}

void FaultSinglePatchTriangulatedSetRepresentationTest::readRepo()
{
RESQML2_NS::TriangulatedSetRepresentation* rep = repo->getDataObjectByUuid<RESQML2_NS::TriangulatedSetRepresentation>(defaultUuid);
REQUIRE(rep->getSeismicSupportOfPatch(0) == nullptr);
REQUIRE(rep->getPatchCount() == 1);
REQUIRE(rep->getRepresentationSetRepresentationCount() == 0);
REQUIRE(rep->getPropertySet().empty());
REQUIRE(rep->getPointsPropertyCount() == 0);
REQUIRE(rep->getSubRepresentationCount() == 0);
REQUIRE(rep->getValuesPropertyCount() == 0);
REQUIRE(rep->getTimeSeries() == nullptr);
REQUIRE(rep->getTitle() == defaultTitle);
REQUIRE(rep->getUuid() == defaultUuid);
REQUIRE(rep->getTriangleCountOfPatch(0) == 20);
REQUIRE_THROWS(rep->getTriangleCountOfPatch(1) == 20);
REQUIRE(rep->getTriangleCountOfAllPatches() == 20);
REQUIRE(rep->getXyzPointCountOfPatch(0) == 18);
REQUIRE_THROWS(rep->getXyzPointCountOfPatch(1) == 18);
REQUIRE(rep->getXyzPointCountOfAllPatches() == 18);

uint32_t triangleNodeIndexFault2[60];
rep->getTriangleNodeIndicesOfPatch(0, triangleNodeIndexFault2);
REQUIRE(std::equal(begin(triangleNodeIndexFault), end(triangleNodeIndexFault), begin(triangleNodeIndexFault2)));

double nodesFaultSinglePatchTriangulatedSetRepresentation2[54];
rep->getXyzPointsOfPatch(0, nodesFaultSinglePatchTriangulatedSetRepresentation2);
REQUIRE(std::equal(begin(nodesFaultSinglePatchTriangulatedSetRepresentation), end(nodesFaultSinglePatchTriangulatedSetRepresentation), begin(nodesFaultSinglePatchTriangulatedSetRepresentation2)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,31 @@ namespace resqml2_test {
protected:
void initRepo();
void readRepo();

private:
static constexpr double nodesFaultSinglePatchTriangulatedSetRepresentation[] = {
150, 0, 200,
150, 100, 200,
150, 200, 200,
250, 0, 300,
250, 100, 300,
250, 200, 300,
300, 0, 350,
300, 100, 350,
300, 200, 350,
450, 0, 500,
450, 100, 500,
450, 200, 500,
500, 0, 550,
500, 100, 550,
500, 200, 550,
600, 0, 650,
600, 100, 650,
600, 200, 650 };
static constexpr uint32_t triangleNodeIndexFault[60] = { 0,4,3, 0,1,4, 1,2,4, 2,5,4,
3,7,6, 3,4,7, 4,5,7, 5,8,7,
6,10,9, 6,7,10, 7,8,10, 8,11,10,
9,13,12, 9,10,13, 10,11,13, 11,14,13,
12,16,15, 12,13,16, 13,14,16, 14,17,16 };
};
}

0 comments on commit e7050c7

Please sign in to comment.