Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gridedit 1336 avoid double computations #378

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions libs/MeshKernelApi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,40 @@ set(VERSION_INC_DIR ${CMAKE_SOURCE_DIR}/tools)

# list of target sources
set(SRC_LIST
${SRC_DIR}/BoundariesAsPolygonCache.cpp
${SRC_DIR}/CachedIntegerValues.cpp
${SRC_DIR}/CachedPointValues.cpp
${SRC_DIR}/FacePolygonPropertyCache.cpp
${SRC_DIR}/HangingEdgeCache.cpp
${SRC_DIR}/MKStateUndoAction.cpp
${SRC_DIR}/MeshKernel.cpp
${SRC_DIR}/NodeInPolygonCache.cpp
${SRC_DIR}/ObtuseTriangleCentreCache.cpp
${SRC_DIR}/PolygonRefinementCache.cpp
${SRC_DIR}/SmallFlowEdgeCentreCache.cpp
)

# list of target headers
set(
INC_LIST
${DOMAIN_INC_DIR}/BoundariesAsPolygonCache.hpp
${DOMAIN_INC_DIR}/BoundingBox.hpp
${DOMAIN_INC_DIR}/CachedIntegerValues.hpp
${DOMAIN_INC_DIR}/CachedPointValues.hpp
${DOMAIN_INC_DIR}/Contacts.hpp
${DOMAIN_INC_DIR}/CurvilinearGrid.hpp
${DOMAIN_INC_DIR}/FacePolygonPropertyCache.hpp
${DOMAIN_INC_DIR}/GeometryList.hpp
${DOMAIN_INC_DIR}/GriddedSamples.hpp
${DOMAIN_INC_DIR}/HangingEdgeCache.hpp
${DOMAIN_INC_DIR}/MKStateUndoAction.hpp
${DOMAIN_INC_DIR}/Mesh1D.hpp
${DOMAIN_INC_DIR}/Mesh2D.hpp
${DOMAIN_INC_DIR}/MeshKernel.hpp
${DOMAIN_INC_DIR}/NodeInPolygonCache.hpp
${DOMAIN_INC_DIR}/ObtuseTriangleCentreCache.hpp
${DOMAIN_INC_DIR}/PolygonRefinementCache.hpp
${DOMAIN_INC_DIR}/SmallFlowEdgeCentreCache.hpp
${DOMAIN_INC_DIR}/State.hpp
${DOMAIN_INC_DIR}/Utils.hpp
${VERSION_INC_DIR}/Version/Version.hpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2024.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// contact: [email protected]
// Stichting Deltares
// P.O. Box 177
// 2600 MH Delft, The Netherlands
//
// All indications and logos of, and references to, "Delft3D" and "Deltares"
// are registered trademarks of Stichting Deltares, and remain the property of
// Stichting Deltares. All rights reserved.
//
//------------------------------------------------------------------------------

#pragma once

#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>

#include "MeshKernelApi/CachedPointValues.hpp"
#include "MeshKernelApi/GeometryList.hpp"
#include "MeshKernelApi/Utils.hpp"

namespace meshkernelapi
{

/// @brief Cache boundary polygon points
class BoundariesAsPolygonCache : public CachedPointValues
{
public:
/// @brief Constructor
BoundariesAsPolygonCache(const int lowerLeftN,
const int lowerLeftM,
const int upperRightN,
const int upperRightM,
const std::vector<meshkernel::Point>& boundaryPoints);

/// @brief Determine if current options match those used to construct the object
bool ValidOptions(const int lowerLeftN,
const int lowerLeftM,
const int upperRightN,
const int upperRightM) const;

private:
int m_lowerLeftNValue = -1; ///< Initial lower left N value
int m_lowerLeftMValue = -1; ///< Initial lower left M value
int m_upperRightNValue = -1; ///< Initial upper right N value
int m_upperRightMValue = -1; ///< Initial upper right M value
};

} // namespace meshkernelapi
64 changes: 64 additions & 0 deletions libs/MeshKernelApi/include/MeshKernelApi/CachedIntegerValues.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2024.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// contact: [email protected]
// Stichting Deltares
// P.O. Box 177
// 2600 MH Delft, The Netherlands
//
// All indications and logos of, and references to, "Delft3D" and "Deltares"
// are registered trademarks of Stichting Deltares, and remain the property of
// Stichting Deltares. All rights reserved.
//
//------------------------------------------------------------------------------

#pragma once

#include <cstring>
#include <vector>

namespace meshkernelapi
{
/// @brief Caches x- and y-coordinate values for various algorithms
class CachedIntegerValues
{
public:
/// @brief Default constructor
CachedIntegerValues() {}

/// @brief Construct with point values
CachedIntegerValues(const std::vector<int>& values);

/// @brief Destructor
virtual ~CachedIntegerValues() = default;

/// @brief Number of points saved
int Size() const
{
return static_cast<int>(m_values.size());
}

/// @brief Copy cached points to geometry
void Copy(int* buffer) const;

protected:
/// @brief Reset the saved integer values.
void Reset(std::vector<int>&& values);

private:
std::vector<int> m_values; ///< integer values
};
} // namespace meshkernelapi
70 changes: 70 additions & 0 deletions libs/MeshKernelApi/include/MeshKernelApi/CachedPointValues.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2024.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// contact: [email protected]
// Stichting Deltares
// P.O. Box 177
// 2600 MH Delft, The Netherlands
//
// All indications and logos of, and references to, "Delft3D" and "Deltares"
// are registered trademarks of Stichting Deltares, and remain the property of
// Stichting Deltares. All rights reserved.
//
//------------------------------------------------------------------------------

#pragma once

#include <cstring>
#include <vector>

#include "MeshKernel/Point.hpp"

#include "MeshKernelApi/GeometryList.hpp"

namespace meshkernelapi
{
/// @brief Caches x- and y-coordinate values for various algorithms
class CachedPointValues
{
public:
/// @brief Default constructor
CachedPointValues() {}

/// @brief Construct with point values
CachedPointValues(const std::vector<meshkernel::Point>& coordinates);

/// @brief Destructor
virtual ~CachedPointValues() = default;

/// @brief Number of points saved
int Size() const
{
return static_cast<int>(m_coordsX.size());
}

/// @brief Copy cached points to geometry
void Copy(const GeometryList& geometry) const;

protected:
/// @brief Reset the saved coordinate values.
void Reset(std::vector<double>&& xValues,
std::vector<double>&& yValues);

private:
std::vector<double> m_coordsX; ///< x-coordinate values
std::vector<double> m_coordsY; ///< y-coordinate values
};
} // namespace meshkernelapi
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2024.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// contact: [email protected]
// Stichting Deltares
// P.O. Box 177
// 2600 MH Delft, The Netherlands
//
// All indications and logos of, and references to, "Delft3D" and "Deltares"
// are registered trademarks of Stichting Deltares, and remain the property of
// Stichting Deltares. All rights reserved.
//
//------------------------------------------------------------------------------

#pragma once

#include <vector>

#include "MeshKernel/Mesh2D.hpp"

#include "MeshKernelApi/CachedPointValues.hpp"

namespace meshkernelapi
{
/// @brief Cache node values of faces
class FacePolygonPropertyCache : public CachedPointValues
{

public:
/// @brief Constructor
FacePolygonPropertyCache(const int propertyValue,
const double minValue,
const double maxValue,
const meshkernel::Mesh2D& mesh,
const int validSize,
const std::vector<bool>& filterMask);

/// @brief Determine if current options match those used to construct the object
bool ValidOptions(const int propertyValue,
const double minValue,
const double maxValue) const;

private:
int m_propertyValue = 0; ///< Initial property value
double m_minimumValue = meshkernel::constants::missing::doubleValue; ///< Initial minimum value
double m_maximumValue = meshkernel::constants::missing::doubleValue; ///< Initial maximum value
};

} // namespace meshkernelapi
48 changes: 48 additions & 0 deletions libs/MeshKernelApi/include/MeshKernelApi/HangingEdgeCache.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2024.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// contact: [email protected]
// Stichting Deltares
// P.O. Box 177
// 2600 MH Delft, The Netherlands
//
// All indications and logos of, and references to, "Delft3D" and "Deltares"
// are registered trademarks of Stichting Deltares, and remain the property of
// Stichting Deltares. All rights reserved.
//
//------------------------------------------------------------------------------

#pragma once

#include <cstring>
#include <vector>

#include "MeshKernel/Point.hpp"

#include "MeshKernelApi/CachedIntegerValues.hpp"

namespace meshkernelapi
{

/// @brief Cache edge indices for hanging nodes/edges
class HangingEdgeCache : public CachedIntegerValues
{
public:
/// @brief Constructor
HangingEdgeCache(const std::vector<meshkernel::UInt>& edgeIds);
};

} // namespace meshkernelapi
Loading
Loading