Skip to content

Commit

Permalink
adding codes for flying-edges algo, still fixing left
Browse files Browse the repository at this point in the history
Signed-off-by: Perminder <[email protected]>
  • Loading branch information
perminder-17 committed Oct 27, 2024
1 parent 69f9bee commit 4b9474b
Show file tree
Hide file tree
Showing 4 changed files with 673 additions and 0 deletions.
149 changes: 149 additions & 0 deletions avogadro/core/cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ Cube::~Cube()
m_lock = nullptr;
}

std::vector<float>::const_iterator
Cube::getRowIter(size_t j, size_t k) const
{
return m_data.cbegin() + m_points.x() * (k * m_points.y() + j);
}


bool Cube::setLimits(const Vector3& min_, const Vector3& max_,
const Vector3i& points)
{
Expand Down Expand Up @@ -194,6 +201,148 @@ float Cube::value(int i, int j, int k) const
return 0.0;
}

std::array<float, 3> Cube::computeGradient(size_t i, size_t j, size_t k) const
{
std::array<std::array<float, 2>, 3> x;
std::array<float, 3> run;

size_t dataIdx = i + j * m_points.x() + k * m_points.x() * m_points.y();

if (i == 0)
{
x[0][0] = m_data[dataIdx + 1];
x[0][1] = m_data[dataIdx];
run[0] = m_spacing[0];
}
else if (i == (m_points.x() - 1))
{
x[0][0] = m_data[dataIdx];
x[0][1] = m_data[dataIdx - 1];
run[0] = m_spacing[0];
}
else
{
x[0][0] = m_data[dataIdx + 1];
x[0][1] = m_data[dataIdx - 1];
run[0] = 2 * m_spacing[0];
}

if (j == 0)
{
x[1][0] = m_data[dataIdx + nx];
x[1][1] = m_data[dataIdx];
run[1] = m_spacing[1];
}
else if (j == (m_points.y() - 1))
{
x[1][0] = m_data[dataIdx];
x[1][1] = m_data[dataIdx - m_points.x()];
run[1] = m_spacing[1];
}
else
{
x[1][0] = m_data[dataIdx + m_points.x()];
x[1][1] = m_data[dataIdx - m_points.x()];
run[1] = 2 * m_spacing[1];
}

if (k == 0)
{
x[2][0] = m_data[dataIdx + m_points.x() * m_points.y()];
x[2][1] = m_data[dataIdx];
run[2] = m_spacing[2];
}
else if (k == (m_points.z() - 1))
{
x[2][0] = m_data[dataIdx];
x[2][1] = m_data[dataIdx - m_points.x() * m_points.y()];
run[2] = m_spacing[2];
}
else
{
x[2][0] = m_data[dataIdx + m_points.x() * m_points.y()];
x[2][1] = m_data[dataIdx - m_points.x() * m_points.y()];
run[2] = 2 * m_spacing[2];
}

std::array<scalar_t, 3> ret;

ret[0] = (x[0][1] - x[0][0]) / run[0];
ret[1] = (x[1][1] - x[1][0]) / run[1];
ret[2] = (x[2][1] - x[2][0]) / run[2];

return ret;
}

std::array<scalar_t, 8> Cube::getValsCube(size_t i, size_t j, size_t k) const
{
std::array<scalar_t, 8> vals;

size_t idx = i + j * m_points.x() + k * m_points.x() * m_points.y();

Check notice on line 281 in avogadro/core/cube.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

avogadro/core/cube.cpp#L281

Variable 'idx' is assigned a value that is never used.

vals[0] = getData(i, j, k);
vals[1] = getData(i + 1, j, k);
vals[2] = getData(i + 1, j + 1, k);
vals[3] = getData(i, j + 1, k);
vals[4] = getData(i, j, k + 1);
vals[5] = getData(i + 1, j, k + 1);
vals[6] = getData(i + 1, j + 1, k + 1);
vals[7] = getData(i, j + 1, k + 1);

return vals;
}


inline scalar_t
Cube::getData(size_t i, size_t j, size_t k) const
{
return m_data[k * m_points.x() * m_points.y() + j * m_points.x() + i];
}


std::array<Vector3, 8> Cube::getPosCube(size_t i, size_t j, size_t k) const
{
std::array<std::array<float, 3>, 8> pos;

float xpos = m_min.x() + i * m_spacing.x();
float ypos = m_min.y() + j * m_spacing.y();
float zpos = m_min.z() + k * m_spacing.z();

pos[0][0] = xpos;
pos[0][1] = ypos;
pos[0][2] = zpos;

pos[1][0] = xpos + m_spacing.x();
pos[1][1] = ypos;
pos[1][2] = zpos;

pos[2][0] = xpos + m_spacing.x();
pos[2][1] = ypos + m_spacing.y();
pos[2][2] = zpos;

pos[3][0] = xpos;
pos[3][1] = ypos + m_spacing.y();
pos[3][2] = zpos;

pos[4][0] = xpos;
pos[4][1] = ypos;
pos[4][2] = zpos + m_spacing.z();

pos[5][0] = xpos + m_spacing.x();
pos[5][1] = ypos;
pos[5][2] = zpos + m_spacing.z();

pos[6][0] = xpos + m_spacing.x();
pos[6][1] = ypos + m_spacing.y();
pos[6][2] = zpos + m_spacing.z();

pos[7][0] = xpos;
pos[7][1] = ypos + m_spacing.y();
pos[7][2] = zpos + m_spacing.z();

return pos;
}

float Cube::value(const Vector3i& pos) const
{
unsigned int index =
Expand Down
4 changes: 4 additions & 0 deletions avogadro/core/cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class AVOGADROCORE_EXPORT Cube
*/
bool addData(const std::vector<float>& values);


std::vector<float>::const_iterator getRowIter(size_t j, size_t k) const;

/**
* @return Index of the point closest to the position supplied.
* @param pos Position to get closest index for.
Expand Down Expand Up @@ -240,6 +243,7 @@ class AVOGADROCORE_EXPORT Cube
Vector3 m_min, m_max, m_spacing;
Vector3i m_points;
float m_minValue, m_maxValue;
std::vector<float> data
std::string m_name;
Type m_cubeType;
Mutex* m_lock;
Expand Down
Loading

0 comments on commit 4b9474b

Please sign in to comment.