Start cleaning Grid class.
This commit is contained in:
parent
4fbe6279d1
commit
d4bb2b2744
27 changed files with 306 additions and 191 deletions
|
@ -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
|
||||
|
|
23
src/core/data_structures/List.h
Normal file
23
src/core/data_structures/List.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
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;
|
||||
};
|
26
src/core/data_structures/ListFactory.cpp
Normal file
26
src/core/data_structures/ListFactory.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include "ListFactory.h"
|
||||
|
||||
#include "ListT.h"
|
||||
#include "Color.h"
|
||||
|
||||
std::unique_ptr<List> ListFactory::Create(List::Type type, std::size_t size)
|
||||
{
|
||||
std::unique_ptr<List> list;
|
||||
if (type == List::Type::DOUBLE)
|
||||
{
|
||||
list = std::make_unique<ListT<double>>(type, size, 0.0);
|
||||
}
|
||||
else if (type == List::Type::UCHAR)
|
||||
{
|
||||
list = std::make_unique<ListT<unsigned char> >(type, size, 0);
|
||||
}
|
||||
else if (type == List::Type::UINT8)
|
||||
{
|
||||
list = std::make_unique<ListT<uint8_t>>(type, size, 0);
|
||||
}
|
||||
else if (type == List::Type::COLOR)
|
||||
{
|
||||
list = std::make_unique<ListT<Color>>(type, size, Color());
|
||||
}
|
||||
return std::move(list);
|
||||
}
|
11
src/core/data_structures/ListFactory.h
Normal file
11
src/core/data_structures/ListFactory.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "List.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class ListFactory
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<List> Create(List::Type type, std::size_t size = 0);
|
||||
};
|
69
src/core/data_structures/ListT.h
Normal file
69
src/core/data_structures/ListT.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
#pragma once
|
||||
|
||||
#include "List.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class ListFactory;
|
||||
|
||||
template<typename T>
|
||||
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<T>& getData() const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
void setData(const std::vector<T>& 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<T> mData;
|
||||
};
|
|
@ -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)
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
#include "Grid.h"
|
||||
|
||||
Grid::Grid(const Bounds& bounds)
|
||||
: mBounds(bounds)
|
||||
{
|
||||
mValues = std::vector<double>(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<double>& Grid::getValues() const
|
||||
{
|
||||
return mValues;
|
||||
}
|
||||
|
||||
void Grid::resetBounds(const Bounds& bounds)
|
||||
{
|
||||
mBounds = bounds;
|
||||
mValues = std::vector<double>(mNumX*mNumY, 0.0);
|
||||
}
|
||||
|
||||
void Grid::setValues(const std::vector<std::size_t>& indices, double value)
|
||||
{
|
||||
for (auto index : indices)
|
||||
{
|
||||
mValues[index] = value;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "Bounds.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class Grid
|
||||
{
|
||||
public:
|
||||
Grid(const Bounds& bounds);
|
||||
|
||||
const Bounds& getBounds() const;
|
||||
|
||||
double getXSpacing() const;
|
||||
|
||||
double getYSpacing() const;
|
||||
|
||||
const std::vector<double>& getValues() const;
|
||||
|
||||
void resetBounds(const Bounds& bounds);
|
||||
|
||||
void setValues(const std::vector<std::size_t>& indices, double value);
|
||||
|
||||
private:
|
||||
Bounds mBounds;
|
||||
std::vector<double> mValues;
|
||||
unsigned mNumX{5};
|
||||
unsigned mNumY{5};
|
||||
};
|
39
src/geometry/grid/AbstractGrid.cpp
Normal file
39
src/geometry/grid/AbstractGrid.cpp
Normal file
|
@ -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();
|
||||
}
|
54
src/geometry/grid/AbstractGrid.h
Normal file
54
src/geometry/grid/AbstractGrid.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#pragma once
|
||||
|
||||
#include "Bounds.h"
|
||||
#include "List.h"
|
||||
#include "ListT.h"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
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<typename T>
|
||||
const std::vector<T> getData() const
|
||||
{
|
||||
if (!dynamic_cast<ListT<T>*>(mData.get()))
|
||||
{
|
||||
throw std::logic_error("Invalid data type request for Grid data.");
|
||||
}
|
||||
|
||||
return dynamic_cast<ListT<T>*>(mData.get())->getData();
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void setData(const std::vector<std::size_t> indices, const std::vector<T>& values)
|
||||
{
|
||||
if (auto list_t = dynamic_cast<ListT<T>*>(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<List> mData;
|
||||
std::size_t mNumX{ 0 };
|
||||
std::size_t mNumY{ 0 };
|
||||
};
|
14
src/geometry/grid/Grid.cpp
Normal file
14
src/geometry/grid/Grid.cpp
Normal file
|
@ -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);
|
||||
}
|
12
src/geometry/grid/Grid.h
Normal file
12
src/geometry/grid/Grid.h
Normal file
|
@ -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;
|
||||
};
|
0
src/geometry/grid/SparseGrid.cpp
Normal file
0
src/geometry/grid/SparseGrid.cpp
Normal file
2
src/geometry/grid/SparseGrid.h
Normal file
2
src/geometry/grid/SparseGrid.h
Normal file
|
@ -0,0 +1,2 @@
|
|||
#pragma once
|
||||
|
|
@ -4,7 +4,6 @@ set(platform_LIB_INCLUDES)
|
|||
|
||||
list(APPEND image_HEADERS
|
||||
Image.h
|
||||
ImageData.h
|
||||
PlatformImage.h
|
||||
PlatformImageWriter.h
|
||||
png/PngWriter.h
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
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<typename T>
|
||||
class ImageDataT : public ImageData
|
||||
{
|
||||
public:
|
||||
virtual Type getType() const override
|
||||
{
|
||||
if (std::is_same<T, unsigned char>::value)
|
||||
{
|
||||
return Type::UCHAR;
|
||||
}
|
||||
else if (std::is_same<T, uint8_t>::value)
|
||||
{
|
||||
return Type::UINT8;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Type::UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T* getDataPtr() const
|
||||
{
|
||||
return mData.data();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const std::vector<T>& getData() const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void setData(const std::vector<T>& data)
|
||||
{
|
||||
mData = data;
|
||||
}
|
||||
|
||||
void setDataItem(std::size_t index, unsigned char item) override
|
||||
{
|
||||
if (index < mData.size())
|
||||
{
|
||||
mData[index] = static_cast<T>(item);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void setDataItem(std::size_t index, T item)
|
||||
{
|
||||
if (index < mData.size())
|
||||
{
|
||||
mData[index] = item;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
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<unsigned char>(mData[index]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t getLength() const override
|
||||
{
|
||||
return mData.size();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<T> mData;
|
||||
};
|
||||
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
0
src/publishing/plotting/EquationNode.cpp
Normal file
0
src/publishing/plotting/EquationNode.cpp
Normal file
0
src/publishing/plotting/EquationNode.h
Normal file
0
src/publishing/plotting/EquationNode.h
Normal file
0
src/publishing/plotting/PlotNode.cpp
Normal file
0
src/publishing/plotting/PlotNode.cpp
Normal file
0
src/publishing/plotting/PlotNode.h
Normal file
0
src/publishing/plotting/PlotNode.h
Normal file
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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<Color>& 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;
|
||||
|
|
|
@ -9,6 +9,7 @@ set(TEST_MODULES
|
|||
core
|
||||
database
|
||||
fonts
|
||||
geometry
|
||||
graphics
|
||||
image
|
||||
ipc
|
||||
|
|
11
test/geometry/CMakeLists.txt
Normal file
11
test/geometry/CMakeLists.txt
Normal file
|
@ -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
|
||||
)
|
10
test/geometry/TestGeometryCollection.cpp
Normal file
10
test/geometry/TestGeometryCollection.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
|
||||
|
||||
TEST_CASE(TestGeometryCollection, "geometry")
|
||||
{
|
||||
|
||||
|
||||
};
|
10
test/geometry/TestGrid.cpp
Normal file
10
test/geometry/TestGrid.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
|
||||
|
||||
TEST_CASE(TestGrid, "geometry")
|
||||
{
|
||||
|
||||
|
||||
};
|
Loading…
Reference in a new issue