Skip to content

Commit

Permalink
MESH transformations added
Browse files Browse the repository at this point in the history
  • Loading branch information
tkoziara committed Jul 16, 2019
1 parent 5c31c39 commit 7148d22
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
69 changes: 68 additions & 1 deletion cpp/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SOFTWARE.
#include <stdio.h>
#include "real.h"
#include "err.h"
#include "alg.h"
#include "solfec.h"

#if PY_MAJOR_VERSION >= 3
Expand Down Expand Up @@ -295,6 +296,51 @@ static int is_tuple_or_list_of_tuples (PyObject *obj, const char *var, size_t *t
return 1;
}

/* transform mesh nodes */
static void dotransform (REAL *transform, size_t type, std::vector<std::array<REAL,3>> &nodes)
{
switch (type)
{
case 3: /* translate */
for (std::vector<std::array<REAL,3>>::iterator it = nodes.begin(); it != nodes.end(); it ++)
{
ACC (*it, transform);
}
break;
case 7: /* axis rotate */
{
REAL rotation[9];
ROTATION_MATRIX (transform+3, transform[7], rotation);
for (std::vector<std::array<REAL,3>>::iterator it = nodes.begin(); it != nodes.end(); it ++)
{
REAL v[3], w[3];
SUB (*it, transform, v);
NVMUL (rotation, v, w);
SCC (w, v);
ACC (*it, w);
}
}
break;
case 9: /* matrix transform */
for (std::vector<std::array<REAL,3>>::iterator it = nodes.begin(); it != nodes.end(); it ++)
{
REAL v[3];
COPY (*it, v);
NVMUL (transform, v, *it);
}
break;
case 4: /* scale */
for (std::vector<std::array<REAL,3>>::iterator it = nodes.begin(); it != nodes.end(); it ++)
{
REAL v[3];
SUB (*it, transform, v);
SCALE (v, transform[3]);
ADD (transform, v, *it);
}
break;
}
}

/* define keywords */
#define KEYWORDS(...) const char *kwl [] = {__VA_ARGS__, NULL}

Expand Down Expand Up @@ -674,7 +720,28 @@ static PyObject* MESH (PyObject *self, PyObject *args, PyObject *kwds)
pmesh->gcolor = PyInt_AsLong (colors);
}

/* TODO: tranform nodes */
/* tranform nodes */
if (PyTuple_Check (transform))
{
REAL trans[9];
size_t type = PyTuple_Size (transform);
for (i = 0; i < type; i ++)
trans[i] = (REAL)PyFloat_AsDouble (PyTuple_GetItem (transform, i)),
dotransform (trans, type, pmesh->nodes);
}
else
{
n = PyList_Size (transform);
for (i = 0; i < n; i ++)
{
REAL trans[9];
PyObject *tuple = PyList_GetItem (transform, i);
size_t type = PyTuple_Size (tuple);
for (j = 0; j < type; j ++)
trans[j] = (REAL)PyFloat_AsDouble (PyTuple_GetItem (tuple, j)),
dotransform (trans, type, pmesh->nodes);
}
}

Py_RETURN_uint64_t (solfec::bodies.size());
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/version.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define VERSION_HASH "b689ed7"
#define VERSION_DATE "2019-07-15"
#define VERSION_HASH "5c31c39"
#define VERSION_DATE "2019-07-16"
16 changes: 16 additions & 0 deletions inc/alg.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ SOFTWARE.
#ifndef __alg__
#define __alg__

#ifndef MIN
#define MIN(v, w) ((v) < (w) ? (v) : (w))
#endif

#ifndef MAX
#define MAX(v, w) ((v) > (w) ? (v) : (w))
#endif

#ifndef SGN
#define SGN(v) ((v) > 0 ? 1 : ((v) < 0 ? -1 : 0))
#endif

#ifndef ABS
#define ABS(v) ((v) > 0 ? (v) : -(v))
#endif

#define ALG_PI 3.14159265358979323846

/* various algebraic macros for small
Expand Down

0 comments on commit 7148d22

Please sign in to comment.