The issue was caused by including both Python.h and BLI_math.h. Since the macro
definition in Python.h was unconditional, it was necessary to include it first and then
BLI_math.h.
Addressing the issue turned out to affect many Freestyle source files. There were several
other coding flaws that complicated the situation:
1. intern/system/FreestyleConfig.h was abused just to include BLI_math.h which was in
fact unnecessary in FreestyleConfig.h. While addressing this, inclusion of both math.h
and BLI_math.h had to be duly dealt with to avoid a compiler error about round().
2. #include <Python.h> was not properly put in the extern "C" { ... } construct.
3. intern/view_map/Interface0D.h and intern/python/Director.h, both of which included
Python.h, were included from within Freestyle header files that were almost or completely
independent of Python. These non-Python header files were used everywhere in the
Freestyle code base, causing many cases of the reported macro redefinitions.
4. The Director.h file was also declaring 'using namespace Freestyle', which was causing
another scope issue in several Freestyle header files.
This commit is intended to address the first problem above. Subsequent commits will deal
with the other three.
176 lines
4.3 KiB
C++
176 lines
4.3 KiB
C++
/*
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
*
|
|
* 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; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* 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, write to the Free Software Foundation,
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
*/
|
|
|
|
/** \file blender/freestyle/intern/scene_graph/NodeTransform.cpp
|
|
* \ingroup freestyle
|
|
* \brief Class to represent a transform node. A Transform node contains one or several children,
|
|
* \brief all affected by the transformation.
|
|
* \author Stephane Grabli
|
|
* \date 06/02/2002
|
|
*/
|
|
|
|
#include "NodeTransform.h"
|
|
|
|
#include "BLI_math.h"
|
|
|
|
namespace Freestyle {
|
|
|
|
void NodeTransform::Translate(real x, real y, real z)
|
|
{
|
|
_Matrix(0, 3) += x;
|
|
_Matrix(1, 3) += y;
|
|
_Matrix(2, 3) += z;
|
|
}
|
|
|
|
void NodeTransform::Rotate(real iAngle, real x, real y, real z)
|
|
{
|
|
//Normalize the x,y,z vector;
|
|
real norm = (real)sqrt(x * x + y * y + z * z);
|
|
if (0 == norm)
|
|
return;
|
|
|
|
x /= norm;
|
|
y /= norm;
|
|
z /= norm;
|
|
|
|
/* find the corresponding matrix with the Rodrigues formula:
|
|
* R = I + sin(iAngle)*Ntilda + (1-cos(iAngle))*Ntilda*Ntilda
|
|
*/
|
|
Matrix33r Ntilda;
|
|
Ntilda(0, 0) = Ntilda(1, 1) = Ntilda(2, 2) = 0.0f;
|
|
Ntilda(0, 1) = -z;
|
|
Ntilda(0, 2) = y;
|
|
Ntilda(1, 0) = z;
|
|
Ntilda(1, 2) = -x;
|
|
Ntilda(2, 0) = -y;
|
|
Ntilda(2, 1) = x;
|
|
|
|
const Matrix33r Ntilda2(Ntilda * Ntilda);
|
|
|
|
|
|
const real sinAngle = (real)sin((iAngle / 180.0f) * M_PI);
|
|
const real cosAngle = (real)cos((iAngle / 180.0f) * M_PI);
|
|
|
|
Matrix33r NS(Ntilda * sinAngle);
|
|
Matrix33r NC(Ntilda2 * (1.0f - cosAngle));
|
|
Matrix33r R;
|
|
R = Matrix33r::identity();
|
|
R += NS + NC;
|
|
|
|
// R4 is the corresponding 4x4 matrix
|
|
Matrix44r R4;
|
|
R4 = Matrix44r::identity();
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
for (int j = 0; j < 3; j++)
|
|
R4(i, j) = R(i, j);
|
|
}
|
|
|
|
// Finally, we multiply our current matrix by R4:
|
|
Matrix44r mat_tmp(_Matrix);
|
|
_Matrix = mat_tmp * R4;
|
|
}
|
|
|
|
void NodeTransform::Scale(real x, real y, real z)
|
|
{
|
|
_Matrix(0, 0) *= x;
|
|
_Matrix(1, 1) *= y;
|
|
_Matrix(2, 2) *= z;
|
|
|
|
_Scaled = true;
|
|
}
|
|
|
|
void NodeTransform::MultiplyMatrix(const Matrix44r &iMatrix)
|
|
{
|
|
Matrix44r mat_tmp(_Matrix);
|
|
_Matrix = mat_tmp * iMatrix;
|
|
}
|
|
|
|
void NodeTransform::setMatrix(const Matrix44r &iMatrix)
|
|
{
|
|
_Matrix = iMatrix;
|
|
if (isScaled(iMatrix))
|
|
_Scaled = true;
|
|
}
|
|
|
|
void NodeTransform::accept(SceneVisitor& v)
|
|
{
|
|
v.visitNodeTransform(*this);
|
|
|
|
v.visitNodeTransformBefore(*this);
|
|
for (vector<Node *>::iterator node = _Children.begin(), end = _Children.end(); node != end; ++node)
|
|
(*node)->accept(v);
|
|
v.visitNodeTransformAfter(*this);
|
|
}
|
|
|
|
void NodeTransform::AddBBox(const BBox<Vec3r>& iBBox)
|
|
{
|
|
Vec3r oldMin(iBBox.getMin());
|
|
Vec3r oldMax(iBBox.getMax());
|
|
|
|
// compute the 8 corners of the bbox
|
|
HVec3r box[8];
|
|
box[0] = HVec3r(iBBox.getMin());
|
|
box[1] = HVec3r(oldMax[0], oldMin[1], oldMin[2]);
|
|
box[2] = HVec3r(oldMax[0], oldMax[1], oldMin[2]);
|
|
box[3] = HVec3r(oldMin[0], oldMax[1], oldMin[2]);
|
|
box[4] = HVec3r(oldMin[0], oldMin[1], oldMax[2]);
|
|
box[5] = HVec3r(oldMax[0], oldMin[1], oldMax[2]);
|
|
box[6] = HVec3r(oldMax[0], oldMax[1], oldMax[2]);
|
|
box[7] = HVec3r(oldMin[0], oldMax[1], oldMax[2]);
|
|
|
|
// Computes the transform iBBox
|
|
HVec3r tbox[8];
|
|
unsigned int i;
|
|
for (i = 0; i < 8; i++)
|
|
tbox[i] = _Matrix * box[i];
|
|
|
|
Vec3r newMin(tbox[0]);
|
|
Vec3r newMax(tbox[0]);
|
|
for (i = 0; i < 8; i++) {
|
|
for (unsigned int j = 0; j < 3; j++) {
|
|
if (newMin[j] > tbox[i][j])
|
|
newMin[j] = tbox[i][j];
|
|
if (newMax[j] < tbox[i][j])
|
|
newMax[j] = tbox[i][j];
|
|
}
|
|
}
|
|
|
|
BBox<Vec3r> transformBox(newMin, newMax);
|
|
|
|
Node::AddBBox(transformBox);
|
|
}
|
|
|
|
bool NodeTransform::isScaled(const Matrix44r &M)
|
|
{
|
|
for (unsigned int j = 0; j < 3; j++) {
|
|
real norm = 0;
|
|
for (unsigned int i = 0; i < 3; i++) {
|
|
norm += M(i, j) * M(i, j);
|
|
}
|
|
if ((norm > 1.01) || (norm < 0.99))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
} /* namespace Freestyle */
|