From d4bb2b274422445863ab137d6e4a3ddbef79711c Mon Sep 17 00:00:00 2001 From: jmsgrogan Date: Mon, 16 Jan 2023 07:40:43 +0000 Subject: [PATCH] Start cleaning Grid class. --- src/core/CMakeLists.txt | 6 ++ src/core/data_structures/List.h | 23 +++++ src/core/data_structures/ListFactory.cpp | 26 ++++++ src/core/data_structures/ListFactory.h | 11 +++ src/core/data_structures/ListT.h | 69 ++++++++++++++ src/geometry/CMakeLists.txt | 10 ++- src/geometry/Grid.cpp | 43 --------- src/geometry/Grid.h | 29 ------ src/geometry/grid/AbstractGrid.cpp | 39 ++++++++ src/geometry/grid/AbstractGrid.h | 54 +++++++++++ src/geometry/grid/Grid.cpp | 14 +++ src/geometry/grid/Grid.h | 12 +++ src/geometry/grid/SparseGrid.cpp | 0 src/geometry/grid/SparseGrid.h | 2 + src/image/CMakeLists.txt | 1 - src/image/ImageData.h | 110 ----------------------- src/publishing/CMakeLists.txt | 4 + src/publishing/plotting/EquationNode.cpp | 0 src/publishing/plotting/EquationNode.h | 0 src/publishing/plotting/PlotNode.cpp | 0 src/publishing/plotting/PlotNode.h | 0 src/visual_elements/nodes/GridNode.cpp | 4 +- src/visual_elements/nodes/GridNode.h | 8 +- test/CMakeLists.txt | 1 + test/geometry/CMakeLists.txt | 11 +++ test/geometry/TestGeometryCollection.cpp | 10 +++ test/geometry/TestGrid.cpp | 10 +++ 27 files changed, 306 insertions(+), 191 deletions(-) create mode 100644 src/core/data_structures/List.h create mode 100644 src/core/data_structures/ListFactory.cpp create mode 100644 src/core/data_structures/ListFactory.h create mode 100644 src/core/data_structures/ListT.h delete mode 100644 src/geometry/Grid.cpp delete mode 100644 src/geometry/Grid.h create mode 100644 src/geometry/grid/AbstractGrid.cpp create mode 100644 src/geometry/grid/AbstractGrid.h create mode 100644 src/geometry/grid/Grid.cpp create mode 100644 src/geometry/grid/Grid.h create mode 100644 src/geometry/grid/SparseGrid.cpp create mode 100644 src/geometry/grid/SparseGrid.h delete mode 100644 src/image/ImageData.h create mode 100644 src/publishing/plotting/EquationNode.cpp create mode 100644 src/publishing/plotting/EquationNode.h create mode 100644 src/publishing/plotting/PlotNode.cpp create mode 100644 src/publishing/plotting/PlotNode.h create mode 100644 test/geometry/CMakeLists.txt create mode 100644 test/geometry/TestGeometryCollection.cpp create mode 100644 test/geometry/TestGrid.cpp diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 1435e0a..0a467e4 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -8,6 +8,11 @@ list(APPEND HEADERS Event.h Color.h CommandLineArgs.h + data_structures/RawTree.h + data_structures/List.h + data_structures/ListT.h + data_structures/ListFactory.h + data_structures/Tree.h encoding/ByteUtils.h encoding/StringUtils.h encoding/UnicodeUtils.h @@ -30,6 +35,7 @@ list(APPEND LIB_INCLUDES CommandLineArgs.cpp data_structures/RawTree.cpp data_structures/Tree.cpp + data_structures/ListFactory.cpp loggers/FileLogger.cpp file_utilities/Directory.cpp file_utilities/File.cpp diff --git a/src/core/data_structures/List.h b/src/core/data_structures/List.h new file mode 100644 index 0000000..8771ab9 --- /dev/null +++ b/src/core/data_structures/List.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +class List +{ +public: + enum class Type + { + UCHAR, + UINT8, + DOUBLE, + COLOR, + LIST, + UNKNOWN + }; + + ~List() = default; + + virtual Type getType() const = 0; + + virtual std::size_t getLength() const = 0; +}; diff --git a/src/core/data_structures/ListFactory.cpp b/src/core/data_structures/ListFactory.cpp new file mode 100644 index 0000000..4ed1f96 --- /dev/null +++ b/src/core/data_structures/ListFactory.cpp @@ -0,0 +1,26 @@ +#include "ListFactory.h" + +#include "ListT.h" +#include "Color.h" + +std::unique_ptr ListFactory::Create(List::Type type, std::size_t size) +{ + std::unique_ptr list; + if (type == List::Type::DOUBLE) + { + list = std::make_unique>(type, size, 0.0); + } + else if (type == List::Type::UCHAR) + { + list = std::make_unique >(type, size, 0); + } + else if (type == List::Type::UINT8) + { + list = std::make_unique>(type, size, 0); + } + else if (type == List::Type::COLOR) + { + list = std::make_unique>(type, size, Color()); + } + return std::move(list); +} \ No newline at end of file diff --git a/src/core/data_structures/ListFactory.h b/src/core/data_structures/ListFactory.h new file mode 100644 index 0000000..4b96b2a --- /dev/null +++ b/src/core/data_structures/ListFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "List.h" + +#include + +class ListFactory +{ +public: + static std::unique_ptr Create(List::Type type, std::size_t size = 0); +}; \ No newline at end of file diff --git a/src/core/data_structures/ListT.h b/src/core/data_structures/ListT.h new file mode 100644 index 0000000..ea41950 --- /dev/null +++ b/src/core/data_structures/ListT.h @@ -0,0 +1,69 @@ +#pragma once + +#include "List.h" + +#include + +class ListFactory; + +template +class ListT : public List +{ +public: + ListT() = delete; + + ListT(List::Type type, std::size_t size, T value) + : mType(type) + { + if (size > 0) + { + initialize(size, value); + } + } + + virtual Type getType() const override + { + return mType; + } + + const T* getDataPtr() const + { + return mData.data(); + } + + const std::vector& getData() const + { + return mData; + } + + void setData(const std::vector& data) + { + mData = data; + } + + void setDataItem(std::size_t index, T item) + { + if (index < mData.size()) + { + mData[index] = item; + } + } + + void initialize(std::size_t size, T value) + { + mData.resize(size); + for (std::size_t idx = 0; idx < size; idx++) + { + mData[idx] = value; + } + } + + std::size_t getLength() const override + { + return mData.size(); + } + +private: + List::Type mType{ List::Type::UNKNOWN }; + std::vector mData; +}; \ No newline at end of file diff --git a/src/geometry/CMakeLists.txt b/src/geometry/CMakeLists.txt index 4f156b1..59fa5a2 100644 --- a/src/geometry/CMakeLists.txt +++ b/src/geometry/CMakeLists.txt @@ -3,7 +3,9 @@ set(MODULE_NAME geometry) list(APPEND HEADERS AbstractGeometricItem.h Bounds.h - Grid.h + grid/AbstractGrid.h + grid/Grid.h + grid/SparseGrid.h math/Linalg.h math/Matrix.h math/Vector.h @@ -22,8 +24,10 @@ list(APPEND HEADERS ) list(APPEND LIB_INCLUDES - Grid.cpp Transform.cpp + grid/AbstractGrid.cpp + grid/Grid.cpp + grid/SparseGrid.cpp math/Linalg.cpp math/Matrix.cpp math/Vector.cpp @@ -49,7 +53,9 @@ target_include_directories(${MODULE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/path ${CMAKE_CURRENT_SOURCE_DIR}/points ${CMAKE_CURRENT_SOURCE_DIR}/primitives + ${CMAKE_CURRENT_SOURCE_DIR}/grid ) +target_link_libraries( ${MODULE_NAME} PUBLIC core) set_target_properties( ${MODULE_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src) diff --git a/src/geometry/Grid.cpp b/src/geometry/Grid.cpp deleted file mode 100644 index b405986..0000000 --- a/src/geometry/Grid.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "Grid.h" - -Grid::Grid(const Bounds& bounds) - : mBounds(bounds) -{ - mValues = std::vector(mNumX*mNumY, 0.0); -} - -const Bounds& Grid::getBounds() const -{ - return mBounds; -} - -double Grid::getXSpacing() const -{ - const auto width = mBounds.mMaxX - mBounds.mMinX; - return width/double(mNumX); -} - -double Grid::getYSpacing() const -{ - const auto height = mBounds.mMaxY - mBounds.mMinY; - return height/double(mNumY); -} - -const std::vector& Grid::getValues() const -{ - return mValues; -} - -void Grid::resetBounds(const Bounds& bounds) -{ - mBounds = bounds; - mValues = std::vector(mNumX*mNumY, 0.0); -} - -void Grid::setValues(const std::vector& indices, double value) -{ - for (auto index : indices) - { - mValues[index] = value; - } -} diff --git a/src/geometry/Grid.h b/src/geometry/Grid.h deleted file mode 100644 index 3577b19..0000000 --- a/src/geometry/Grid.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "Bounds.h" - -#include - -class Grid -{ -public: - Grid(const Bounds& bounds); - - const Bounds& getBounds() const; - - double getXSpacing() const; - - double getYSpacing() const; - - const std::vector& getValues() const; - - void resetBounds(const Bounds& bounds); - - void setValues(const std::vector& indices, double value); - -private: - Bounds mBounds; - std::vector mValues; - unsigned mNumX{5}; - unsigned mNumY{5}; -}; diff --git a/src/geometry/grid/AbstractGrid.cpp b/src/geometry/grid/AbstractGrid.cpp new file mode 100644 index 0000000..5e0c460 --- /dev/null +++ b/src/geometry/grid/AbstractGrid.cpp @@ -0,0 +1,39 @@ +#include "AbstractGrid.h" + +#include "ListT.h" + +AbstractGrid::AbstractGrid(const Bounds& bounds, std::size_t numPointsX, std::size_t numPointsY, List::Type dataType) + : mBounds(bounds), + mNumX(numPointsX), + mNumY(numPointsY) +{ + +} + +const Bounds& AbstractGrid::getBounds() const +{ + return mBounds; +} + +double AbstractGrid::getXSpacing() const +{ + const auto width = mBounds.mMaxX - mBounds.mMinX; + return width / double(mNumX); +} + +double AbstractGrid::getYSpacing() const +{ + const auto height = mBounds.mMaxY - mBounds.mMinY; + return height / double(mNumY); +} + +void AbstractGrid::resetBounds(const Bounds& bounds) +{ + mBounds = bounds; + initializeData(mData->getType()); +} + +List::Type AbstractGrid::getDataType() +{ + return mData->getType(); +} \ No newline at end of file diff --git a/src/geometry/grid/AbstractGrid.h b/src/geometry/grid/AbstractGrid.h new file mode 100644 index 0000000..822d054 --- /dev/null +++ b/src/geometry/grid/AbstractGrid.h @@ -0,0 +1,54 @@ +#pragma once + +#include "Bounds.h" +#include "List.h" +#include "ListT.h" + +#include +#include +#include + +class AbstractGrid +{ +public: + AbstractGrid(const Bounds& bounds, std::size_t numPointsX, std::size_t numPointsY, List::Type dataType = List::Type::DOUBLE); + + const Bounds& getBounds() const; + + double getXSpacing() const; + + double getYSpacing() const; + + List::Type getDataType(); + + template + const std::vector getData() const + { + if (!dynamic_cast*>(mData.get())) + { + throw std::logic_error("Invalid data type request for Grid data."); + } + + return dynamic_cast*>(mData.get())->getData(); + + } + + template + void setData(const std::vector indices, const std::vector& values) + { + if (auto list_t = dynamic_cast*>(mData.get())) + { + list_t->setData(indices, values); + } + } + + virtual void initializeData(List::Type dataType) = 0; + + void resetBounds(const Bounds& bounds); + +protected: + Bounds mBounds; + std::unique_ptr mData; + std::size_t mNumX{ 0 }; + std::size_t mNumY{ 0 }; +}; \ No newline at end of file diff --git a/src/geometry/grid/Grid.cpp b/src/geometry/grid/Grid.cpp new file mode 100644 index 0000000..7d280b5 --- /dev/null +++ b/src/geometry/grid/Grid.cpp @@ -0,0 +1,14 @@ +#include "Grid.h" + +#include "ListFactory.h" + +Grid::Grid(const Bounds& bounds, std::size_t numPointsX, std::size_t numPointsY, List::Type dataType) + : AbstractGrid(bounds, numPointsX, numPointsY, dataType) +{ + initializeData(dataType); +} + +void Grid::initializeData(List::Type dataType) +{ + mData = ListFactory::Create(dataType, mNumX * mNumY); +} \ No newline at end of file diff --git a/src/geometry/grid/Grid.h b/src/geometry/grid/Grid.h new file mode 100644 index 0000000..42c4050 --- /dev/null +++ b/src/geometry/grid/Grid.h @@ -0,0 +1,12 @@ +#pragma once + +#include "AbstractGrid.h" + +class Grid : public AbstractGrid +{ +public: + Grid(const Bounds& bounds, std::size_t numPointsX, std::size_t numPointsY, List::Type dataType = List::Type::DOUBLE); + +private: + void initializeData(List::Type dataType) override; +}; diff --git a/src/geometry/grid/SparseGrid.cpp b/src/geometry/grid/SparseGrid.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/geometry/grid/SparseGrid.h b/src/geometry/grid/SparseGrid.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/src/geometry/grid/SparseGrid.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/src/image/CMakeLists.txt b/src/image/CMakeLists.txt index 81f01b3..6816b6b 100644 --- a/src/image/CMakeLists.txt +++ b/src/image/CMakeLists.txt @@ -4,7 +4,6 @@ set(platform_LIB_INCLUDES) list(APPEND image_HEADERS Image.h - ImageData.h PlatformImage.h PlatformImageWriter.h png/PngWriter.h diff --git a/src/image/ImageData.h b/src/image/ImageData.h deleted file mode 100644 index 487523f..0000000 --- a/src/image/ImageData.h +++ /dev/null @@ -1,110 +0,0 @@ -#pragma once - -#include -#include - -class ImageData -{ -public: - enum class Type - { - UCHAR, - UINT8, - UNKNOWN - }; - - virtual Type getType() const = 0; - - virtual void setDataItem(std::size_t index, unsigned char item) = 0; - - virtual unsigned char getAsUnsignedChar(std::size_t index) const = 0; - - virtual std::size_t getLength() const = 0; -}; - -template -class ImageDataT : public ImageData -{ -public: - virtual Type getType() const override - { - if (std::is_same::value) - { - return Type::UCHAR; - } - else if (std::is_same::value) - { - return Type::UINT8; - } - else - { - return Type::UNKNOWN; - } - } - - template - const T* getDataPtr() const - { - return mData.data(); - } - - template - const std::vector& getData() const - { - return mData; - } - - template - void setData(const std::vector& data) - { - mData = data; - } - - void setDataItem(std::size_t index, unsigned char item) override - { - if (index < mData.size()) - { - mData[index] = static_cast(item); - } - } - - template - void setDataItem(std::size_t index, T item) - { - if (index < mData.size()) - { - mData[index] = item; - } - } - - template - void initialize(std::size_t size, T value) - { - mData.resize(size); - for (std::size_t idx = 0; idx < size; idx++) - { - mData[idx] = value; - } - } - - unsigned char getAsUnsignedChar(std::size_t index) const override - { - if (index < mData.size()) - { - return static_cast(mData[index]); - } - else - { - return 0; - } - } - - std::size_t getLength() const override - { - return mData.size(); - } - -private: - std::vector mData; -}; - diff --git a/src/publishing/CMakeLists.txt b/src/publishing/CMakeLists.txt index fe4e023..a25150f 100644 --- a/src/publishing/CMakeLists.txt +++ b/src/publishing/CMakeLists.txt @@ -11,6 +11,8 @@ list(APPEND publishing_HEADERS pdf/PdfWriter.h plotting/GraphPlotter.h plotting/SvgConverter.h + plotting/PlotNode.h + plotting/EquationNode.h latex/LatexDocument.h latex/LatexMathExpression.h latex/LatexSymbols.h @@ -33,6 +35,8 @@ list(APPEND publishing_LIB_INCLUDES latex/LatexSymbols.cpp plotting/GraphPlotter.h plotting/SvgConverter.cpp + plotting/PlotNode.cpp + plotting/EquationNode.cpp DocumentConverter.cpp ) diff --git a/src/publishing/plotting/EquationNode.cpp b/src/publishing/plotting/EquationNode.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/publishing/plotting/EquationNode.h b/src/publishing/plotting/EquationNode.h new file mode 100644 index 0000000..e69de29 diff --git a/src/publishing/plotting/PlotNode.cpp b/src/publishing/plotting/PlotNode.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/publishing/plotting/PlotNode.h b/src/publishing/plotting/PlotNode.h new file mode 100644 index 0000000..e69de29 diff --git a/src/visual_elements/nodes/GridNode.cpp b/src/visual_elements/nodes/GridNode.cpp index 9783864..569f3f2 100644 --- a/src/visual_elements/nodes/GridNode.cpp +++ b/src/visual_elements/nodes/GridNode.cpp @@ -8,7 +8,7 @@ GridNode::GridNode(const Point& location) } -void GridNode::setNumX(unsigned numX) +void GridNode::setNumX(std::size_t numX) { if (mNumberX != numX) { @@ -17,7 +17,7 @@ void GridNode::setNumX(unsigned numX) } } -void GridNode::setNumY(unsigned numY) +void GridNode::setNumY(std::size_t numY) { if (mNumberY != numY) { diff --git a/src/visual_elements/nodes/GridNode.h b/src/visual_elements/nodes/GridNode.h index 359a913..81ae1bb 100644 --- a/src/visual_elements/nodes/GridNode.h +++ b/src/visual_elements/nodes/GridNode.h @@ -9,9 +9,9 @@ class GridNode : public MaterialNode public: GridNode(const Point& location); - void setNumX(unsigned numX); + void setNumX(std::size_t numX); - void setNumY(unsigned numY); + void setNumY(std::size_t numY); void setData(const std::vector& colors); @@ -24,8 +24,8 @@ public: void setHeight(double height); private: - unsigned mNumberX{5}; - unsigned mNumberY{5}; + std::size_t mNumberX{5}; + std::size_t mNumberY{5}; double mWidth{1}; double mHeight{1}; bool mDataDirty = true; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7f4de71..7970c78 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,6 +9,7 @@ set(TEST_MODULES core database fonts + geometry graphics image ipc diff --git a/test/geometry/CMakeLists.txt b/test/geometry/CMakeLists.txt new file mode 100644 index 0000000..841c72d --- /dev/null +++ b/test/geometry/CMakeLists.txt @@ -0,0 +1,11 @@ + +set(GEOMETRY_UNIT_TEST_FILES + geometry/TestGeometryCollection.cpp + geometry/TestGrid.cpp + PARENT_SCOPE + ) + +set(GEOMETRY_UNIT_TEST_DEPENDENCIES + geometry + PARENT_SCOPE + ) \ No newline at end of file diff --git a/test/geometry/TestGeometryCollection.cpp b/test/geometry/TestGeometryCollection.cpp new file mode 100644 index 0000000..19f7c13 --- /dev/null +++ b/test/geometry/TestGeometryCollection.cpp @@ -0,0 +1,10 @@ +#include "TestFramework.h" +#include "TestUtils.h" + + + +TEST_CASE(TestGeometryCollection, "geometry") +{ + + +}; \ No newline at end of file diff --git a/test/geometry/TestGrid.cpp b/test/geometry/TestGrid.cpp new file mode 100644 index 0000000..6bd5acb --- /dev/null +++ b/test/geometry/TestGrid.cpp @@ -0,0 +1,10 @@ +#include "TestFramework.h" +#include "TestUtils.h" + + + +TEST_CASE(TestGrid, "geometry") +{ + + +}; \ No newline at end of file