Merged mfeemster/fractorium into master

This commit is contained in:
Michel Mastriani 2019-05-29 07:16:06 -03:00
commit f852f935a5
9 changed files with 234 additions and 226 deletions

View File

@ -212,7 +212,7 @@ enum class eVariationId : et
VAR_GLYNNSIM3 , VAR_GLYNNSIM3 ,
VAR_GLYNNSIM4 , VAR_GLYNNSIM4 ,
VAR_GLYNNSIM5 , VAR_GLYNNSIM5 ,
VAR_GNARLY , VAR_GNARLY,
VAR_GRIDOUT , VAR_GRIDOUT ,
VAR_HANDKERCHIEF, VAR_HANDKERCHIEF,
VAR_HEART , VAR_HEART ,

View File

@ -4515,9 +4515,7 @@ public:
T b = helper.In.y - m_Cy; T b = helper.In.y - m_Cy;
T c = 1 - m_Cx * helper.In.x - m_Cy * helper.In.y; T c = 1 - m_Cx * helper.In.x - m_Cy * helper.In.y;
T d = m_Cy * helper.In.x - m_Cx * helper.In.y; T d = m_Cy * helper.In.x - m_Cx * helper.In.y;
T num = m_Weight / Zeps(c * c + d * d); T num = m_Weight / Zeps(c * c + d * d);
helper.Out.x = (a * c + b * d) * num; helper.Out.x = (a * c + b * d) * num;
helper.Out.y = (b * c - a * d) * num; helper.Out.y = (b * c - a * d) * num;
helper.Out.z = DefaultZ(helper); helper.Out.z = DefaultZ(helper);
@ -4534,16 +4532,15 @@ public:
string cQ = "parVars[" + ToUpper(m_Params[i++].Name()) + index; string cQ = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
string cX = "parVars[" + ToUpper(m_Params[i++].Name()) + index; string cX = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
string cY = "parVars[" + ToUpper(m_Params[i++].Name()) + index; string cY = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
ss << "\t{\n" ss << "\t{\n"
<< "\t\treal_t a = vIn.x - " << cX << ";\n" << "\t\treal_t a = vIn.x - " << cX << ";\n"
<< "\t\treal_t b = vIn.y - " << cY << ";\n" << "\t\treal_t b = vIn.y - " << cY << ";\n"
<< "\t\treal_t c = 1 - " << cX << " * vIn.x - " << cY << " * vIn.y;\n" << "\t\treal_t c = 1 - " << cX << " * vIn.x - " << cY << " * vIn.y;\n"
<< "\t\treal_t d = " << cY <<" * vIn.x - " << cX << " * vIn.y;\n" << "\t\treal_t d = fma(" << cY << ", vIn.x, -(" << cX << " * vIn.y));\n"
<< "\t\treal_t num = " << weight <<" / Zeps(c * c + d * d);\n" << "\t\treal_t num = " << weight << " / Zeps(fma(c, c, d * d));\n"
<< "\n" << "\n"
<< "\t\tvOut.x = (a * c + b * d) * num;\n" << "\t\tvOut.x = fma(a, c, b * d) * num;\n"
<< "\t\tvOut.y = (b * c - a * d) * num;\n" << "\t\tvOut.y = fma(b, c, -(a * d)) * num;\n"
<< "\t\tvOut.z = " << DefaultZCl() << "\t\tvOut.z = " << DefaultZCl()
<< "\t}\n"; << "\t}\n";
return ss.str(); return ss.str();

View File

@ -1108,7 +1108,7 @@ public:
T temp, x = helper.In.x / m_Width; T temp, x = helper.In.x / m_Width;
bool pos = x > 0; bool pos = x > 0;
if (std::cos((pos ? x - (int)x : x + (int)x) * M_PI) < rand.Frand01<T>() * 2 - 1) if (std::cos((pos ? x - (int)x : x + (int)x) * T(M_PI)) < rand.Frand01<T>() * 2 - 1)
temp = pos ? -m_Vwidth : m_Vwidth; temp = pos ? -m_Vwidth : m_Vwidth;
else else
temp = 0; temp = 0;
@ -4280,11 +4280,11 @@ public:
virtual void Func(IteratorHelper<T>& helper, Point<T>& outPoint, QTIsaac<ISAAC_SIZE, ISAAC_INT>& rand) override virtual void Func(IteratorHelper<T>& helper, Point<T>& outPoint, QTIsaac<ISAAC_SIZE, ISAAC_INT>& rand) override
{ {
v2T z1(helper.In.x, helper.In.y); std::complex<T> z(helper.In.x, helper.In.y);
v2T z = VarFuncs<T>::RealDivComplex(1.0, z1); z = T(1.0) / z;
v2T result = VarFuncs<T>::ComplexMultReal(VarFuncs<T>::ComplexLog(VarFuncs<T>::ComplexPlusComplex(z, VarFuncs<T>::ComplexMultComplex(VarFuncs<T>::ComplexSqrt(VarFuncs<T>::ComplexPlusReal(z, 1.0)), VarFuncs<T>::ComplexSqrt(VarFuncs<T>::ComplexMinusReal(z, 1.0))))), m_WeightInvPi); std::complex<T> result = m_WeightInvPi * std::log(z + std::sqrt(z + T(1.0)) * std::sqrt(z - T(1.0)));
helper.Out.x = result.x; helper.Out.x = result.real();
helper.Out.y = result.y; helper.Out.y = result.imag();
helper.Out.z = DefaultZ(helper); helper.Out.z = DefaultZ(helper);
} }
@ -4347,19 +4347,19 @@ public:
virtual void Func(IteratorHelper<T>& helper, Point<T>& outPoint, QTIsaac<ISAAC_SIZE, ISAAC_INT>& rand) override virtual void Func(IteratorHelper<T>& helper, Point<T>& outPoint, QTIsaac<ISAAC_SIZE, ISAAC_INT>& rand) override
{ {
v2T z1(helper.In.x, helper.In.y); std::complex<T> z(helper.In.x, helper.In.y);
v2T z = VarFuncs<T>::RealDivComplex(1.0, z1); z = T(1.0) / z;
v2T result = VarFuncs<T>::ComplexMultReal(VarFuncs<T>::ComplexLog(VarFuncs<T>::ComplexPlusComplex(z, VarFuncs<T>::ComplexMultComplex(VarFuncs<T>::ComplexSqrt(VarFuncs<T>::ComplexPlusReal(z, 1.0)), VarFuncs<T>::ComplexSqrt(VarFuncs<T>::ComplexMinusReal(z, 1.0))))), m_WeightInvPi); std::complex<T> result = m_WeightInvPi * std::log(z + std::sqrt(z + T(1.0)) * std::sqrt(z - T(1.0)));
if (result.y < 0) if (result.imag() < 0)
{ {
helper.Out.x = result.x; helper.Out.x = result.real();
helper.Out.y = result.y + 1; helper.Out.y = result.imag() + T(1.0);
} }
else else
{ {
helper.Out.x = -result.x; helper.Out.x = -result.real();
helper.Out.y = result.y - 1; helper.Out.y = result.imag() - T(1.0);
} }
helper.Out.z = DefaultZ(helper); helper.Out.z = DefaultZ(helper);
@ -4433,10 +4433,10 @@ public:
virtual void Func(IteratorHelper<T>& helper, Point<T>& outPoint, QTIsaac<ISAAC_SIZE, ISAAC_INT>& rand) override virtual void Func(IteratorHelper<T>& helper, Point<T>& outPoint, QTIsaac<ISAAC_SIZE, ISAAC_INT>& rand) override
{ {
v2T z(helper.In.x, helper.In.y); std::complex<T> z(helper.In.x, helper.In.y);
v2T result = VarFuncs<T>::ComplexMultReal(VarFuncs<T>::ComplexLog(VarFuncs<T>::ComplexPlusComplex(z, VarFuncs<T>::ComplexSqrt(VarFuncs<T>::ComplexPlusReal(VarFuncs<T>::ComplexMultComplex(z, z), 1.0)))), m_WeightInvPi); std::complex<T> result = m_WeightInvPi * std::log(z + std::sqrt(z * z + T(1.0)));
helper.Out.x = result.x; helper.Out.x = result.real();
helper.Out.y = result.y; helper.Out.y = result.imag();
helper.Out.z = DefaultZ(helper); helper.Out.z = DefaultZ(helper);
} }
@ -4497,11 +4497,10 @@ public:
virtual void Func(IteratorHelper<T>& helper, Point<T>& outPoint, QTIsaac<ISAAC_SIZE, ISAAC_INT>& rand) override virtual void Func(IteratorHelper<T>& helper, Point<T>& outPoint, QTIsaac<ISAAC_SIZE, ISAAC_INT>& rand) override
{ {
v2T z(helper.In.x, helper.In.y); std::complex<T> z(helper.In.x, helper.In.y);
v2T zm(-helper.In.x, -helper.In.y); std::complex<T> result = m_WeightInvPi * std::log((z + T(1.0)) / (-z + T(1.0)));
v2T result = VarFuncs<T>::ComplexMultReal(VarFuncs<T>::ComplexLog(VarFuncs<T>::ComplexDivComplex(VarFuncs<T>::ComplexPlusReal(z, 1.0), VarFuncs<T>::ComplexPlusReal(zm, 1.0))), m_WeightInvPi); helper.Out.x = result.real();
helper.Out.x = result.x; helper.Out.y = result.imag();
helper.Out.y = result.y;
helper.Out.z = DefaultZ(helper); helper.Out.z = DefaultZ(helper);
} }
@ -7096,7 +7095,6 @@ public:
T Cx, Cy; T Cx, Cy;
T Lx, Ly; T Lx, Ly;
T r, theta, s, c; T r, theta, s, c;
Vx = helper.In.x; Vx = helper.In.x;
Vy = helper.In.y; Vy = helper.In.y;
@ -7104,7 +7102,6 @@ public:
{ {
Cx = (Floor<T>(Vx / m_GnarlyCellSize) + T(0.5)) * m_GnarlyCellSize; Cx = (Floor<T>(Vx / m_GnarlyCellSize) + T(0.5)) * m_GnarlyCellSize;
Cy = (Floor<T>(Vy / m_GnarlyCellSize) + T(0.5)) * m_GnarlyCellSize; Cy = (Floor<T>(Vy / m_GnarlyCellSize) + T(0.5)) * m_GnarlyCellSize;
Lx = Vx - Cx; Lx = Vx - Cx;
Ly = Vy - Cy; Ly = Vy - Cy;
@ -7118,8 +7115,8 @@ public:
} }
} }
helper.Out.x += m_Weight * Vx; helper.Out.x = m_Weight * Vx;
helper.Out.y += m_Weight * Vy; helper.Out.y = m_Weight * Vy;
helper.Out.z = DefaultZ(helper); helper.Out.z = DefaultZ(helper);
} }
@ -7134,7 +7131,7 @@ public:
string twist = "parVars[" + ToUpper(m_Params[i++].Name()) + index; string twist = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
string r2 = "parVars[" + ToUpper(m_Params[i++].Name()) + index; string r2 = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
ss << "\t{\n" ss << "\t{\n"
<< "\t\treal_t Vx, Vy, Cx, Cy, Lx, Ly;\n" << "\t\treal_t Vx, Vy, Cx, Cy, Lx, Ly, Lxy;\n"
<< "\t\treal_t r, theta, s, c;\n" << "\t\treal_t r, theta, s, c;\n"
<< "\n" << "\n"
<< "\t\tVx = vIn.x;\n" << "\t\tVx = vIn.x;\n"
@ -7147,10 +7144,11 @@ public:
<< "\n" << "\n"
<< "\t\t\tLx = Vx - Cx;\n" << "\t\t\tLx = Vx - Cx;\n"
<< "\t\t\tLy = Vy - Cy;\n" << "\t\t\tLy = Vy - Cy;\n"
<< "\t\t\tLxy = fma(Lx, Lx, Ly * Ly);\n"
<< "\n" << "\n"
<< "\t\t\tif ((Lx * Lx + Ly * Ly) <= " << r2 << ")\n" << "\t\t\tif (Lxy <= " << r2 << ")\n"
<< "\t\t\t{\n" << "\t\t\t{\n"
<< "\t\t\t\tr = (Lx * Lx + Ly * Ly) / " << r2 << ";\n" << "\t\t\t\tr = Lxy / " << r2 << ";\n"
<< "\t\t\t\ttheta = " << twist << " * log(r);\n" << "\t\t\t\ttheta = " << twist << " * log(r);\n"
<< "\t\t\t\ts = sin(theta);\n" << "\t\t\t\ts = sin(theta);\n"
<< "\t\t\t\tc = cos(theta);\n" << "\t\t\t\tc = cos(theta);\n"
@ -7159,8 +7157,8 @@ public:
<< "\t\t\t}\n" << "\t\t\t}\n"
<< "\t\t}\n" << "\t\t}\n"
<< "\n" << "\n"
<< "\t\tvOut.x += " << weight << " * Vx;\n" << "\t\tvOut.x = " << weight << " * Vx;\n"
<< "\t\tvOut.y += " << weight << " * Vy;\n" << "\t\tvOut.y = " << weight << " * Vy;\n"
<< "\t\tvOut.z = " << DefaultZCl() << "\t\tvOut.z = " << DefaultZCl()
<< "\t}\n"; << "\t}\n";
return ss.str(); return ss.str();
@ -7169,7 +7167,7 @@ public:
virtual void Precalc() override virtual void Precalc() override
{ {
T radius = T(0.5) * m_GnarlyCellSize; T radius = T(0.5) * m_GnarlyCellSize;
m_R2 = Zeps(radius * radius); m_R2 = Zeps(SQR(radius));
} }
protected: protected:

View File

@ -961,7 +961,9 @@ bool XmlToEmber<T>::ParseEmberElementFromChaos(xmlNode* emberNode, Ember<T>& cur
} }
else if (parvar) else if (parvar)
{ {
if (!StartsWith(paramstr, prefix))
paramstr = prefix + paramstr; paramstr = prefix + paramstr;
parvar->SetParamVal(paramstr.c_str(), val); parvar->SetParamVal(paramstr.c_str(), val);
//if (!parvar->SetParamVal(paramstr.c_str(), val)) //if (!parvar->SetParamVal(paramstr.c_str(), val))
// AddToReport(string(loc) + " : Failed to set parametric variation parameter " + paramstr); // AddToReport(string(loc) + " : Failed to set parametric variation parameter " + paramstr);

View File

@ -20,7 +20,6 @@ CurvesGraphicsView::CurvesGraphicsView(QWidget* parent)
m_GPen.setWidth(2); m_GPen.setWidth(2);
m_BPen.setWidth(2); m_BPen.setWidth(2);
setScene(&m_Scene); setScene(&m_Scene);
SetTop(CurveIndex::ALL);
//qDebug() << "Original scene rect before setting anything is: " << sceneRect(); //qDebug() << "Original scene rect before setting anything is: " << sceneRect();
m_OriginalRect = sceneRect(); m_OriginalRect = sceneRect();
Curves<float> curves(true); Curves<float> curves(true);
@ -30,16 +29,19 @@ CurvesGraphicsView::CurvesGraphicsView(QWidget* parent)
} }
/// <summary> /// <summary>
/// Get the position of a given point within a given curve. /// Called when an underlying point has had its position changed, so emit a signal so that a listener can take action.
/// </summary> /// </summary>
/// <param name="curveIndex">The curve whose point value will be retrieved, 0-3.</param> /// <param name="curveIndex">The curve whose point value was changed, 0-3.</param>
/// <param name="pointIndex">The point within the curve value will be retrieved, 1-2.</param> /// <param name="pointIndex">The point within the curve whose point value was changed.</param>
/// <param name="point">The position of the point. X,Y will each be within 0-1.</param> /// <param name="point">The position of the point. X,Y will each be within 0-1.</param>
void CurvesGraphicsView::PointChanged(int curveIndex, int pointIndex, const QPointF& point) void CurvesGraphicsView::PointChanged(int curveIndex, int pointIndex, const QPointF& point)
{ {
if (curveIndex == m_Index)
{
double x = point.x() / width(); double x = point.x() / width();
double y = (height() - point.y()) / height(); double y = (height() - point.y()) / height();
emit PointChangedSignal(curveIndex, pointIndex, QPointF(x, y)); emit PointChangedSignal(curveIndex, pointIndex, QPointF(x, y));
}
} }
/// <summary> /// <summary>
@ -105,6 +107,7 @@ void CurvesGraphicsView::Set(Curves<float>& curves)
createpoints(1, m_RedP, Qt::GlobalColor::red, 1); createpoints(1, m_RedP, Qt::GlobalColor::red, 1);
createpoints(2, m_GrnP, Qt::GlobalColor::green, 1); createpoints(2, m_GrnP, Qt::GlobalColor::green, 1);
createpoints(3, m_BluP, Qt::GlobalColor::blue, 1); createpoints(3, m_BluP, Qt::GlobalColor::blue, 1);
SetTop(CurveIndex(m_Index));
} }
/// <summary> /// <summary>
@ -135,16 +138,10 @@ void CurvesGraphicsView::SetTop(CurveIndex curveIndex)
for (size_t i = 0; i < 4; i++) for (size_t i = 0; i < 4; i++)
{ {
if (i == m_Index) bool b = (i == m_Index);
{
for (auto& p : m_Points[i]) for (auto& p : m_Points[i])
p->setZValue(2); p->SetCurrent(b);
}
else
{
for (auto& p : m_Points[i])
p->setZValue(1);
}
} }
} }
@ -237,7 +234,7 @@ void CurvesGraphicsView::mousePressEvent(QMouseEvent* e)
return -1; return -1;
}; };
if (e->button() == Qt::RightButton)//Right button does whole image rotation and scaling. if (e->button() == Qt::RightButton)
{ {
int i = findpoint(e->pos().x(), e->pos().y()); int i = findpoint(e->pos().x(), e->pos().y());

View File

@ -39,6 +39,7 @@ public:
void Set(int curveIndex, int pointIndex, const QPointF& point); void Set(int curveIndex, int pointIndex, const QPointF& point);
void Set(Curves<float>& curves); void Set(Curves<float>& curves);
void SetTop(CurveIndex curveIndex); void SetTop(CurveIndex curveIndex);
size_t SelectedCurveIndex() const { return m_Index; }
Q_SIGNALS: Q_SIGNALS:
void PointChangedSignal(int curveIndex, int pointIndex, const QPointF& point); void PointChangedSignal(int curveIndex, int pointIndex, const QPointF& point);
@ -87,13 +88,23 @@ public:
EllipseItem(const QRectF& rect, int curveIndex, int pointIndex, CurvesGraphicsView* viewParent, QGraphicsItem* parent = nullptr) EllipseItem(const QRectF& rect, int curveIndex, int pointIndex, CurvesGraphicsView* viewParent, QGraphicsItem* parent = nullptr)
: QGraphicsEllipseItem(rect, parent) : QGraphicsEllipseItem(rect, parent)
{ {
m_CurveIndex = curveIndex;
m_PointIndex = pointIndex;
m_ViewParent = viewParent;
setFlag(QGraphicsItem::ItemSendsScenePositionChanges); setFlag(QGraphicsItem::ItemSendsScenePositionChanges);
setFlag(QGraphicsItem::ItemIsSelectable); setFlag(QGraphicsItem::ItemIsSelectable);
setFlag(QGraphicsItem::ItemIsMovable); setFlag(QGraphicsItem::ItemIsMovable);
setPen(Qt::NoPen); setPen(Qt::NoPen);
m_CurveIndex = curveIndex; }
m_PointIndex = pointIndex;
m_ViewParent = viewParent; /// <summary>
/// Set whether this item is selectable, which means this curve is the current one.
/// </summary>
/// <param name="b">True if selected, else false.</param>
void SetCurrent(bool b)
{
setFlag(QGraphicsItem::ItemIsMovable, b);
setZValue(b ? 2 : 1);
} }
/// <summary> /// <summary>
@ -125,7 +136,7 @@ protected:
/// <returns>The new position</returns> /// <returns>The new position</returns>
virtual QVariant itemChange(GraphicsItemChange change, const QVariant& value) override virtual QVariant itemChange(GraphicsItemChange change, const QVariant& value) override
{ {
if (change == ItemPositionChange && scene()) if ((change == ItemPositionChange) && scene())
{ {
//Value is the new position. //Value is the new position.
QPointF newPos = value.toPointF(); QPointF newPos = value.toPointF();

View File

@ -19,9 +19,11 @@ namespace apoconv
{ "(float)", "" }, { "(float)", "" },
{ "double", "T" }, { "double", "T" },
{ "float", "T" }, { "float", "T" },
{ "Complex", "std::complex<T>" },
//{ "0.0", "0" }, //{ "0.0", "0" },
{ "0.5", "T(0.5)" }, { "0.5", "T(0.5)" },
{ "1.0", "T(1.0)" }, { "1.0", "T(1.0)" },
{ "2.0", "T(2.0)" },
{ "0.1", "T(0.1)" }, { "0.1", "T(0.1)" },
{ "0.01", "T(0.01)" }, { "0.01", "T(0.01)" },
{ "0.001", "T(0.001)" }, { "0.001", "T(0.001)" },
@ -56,6 +58,7 @@ namespace apoconv
{ "sqrt(", "std::sqrt(" }, { "sqrt(", "std::sqrt(" },
{ "pow(", "std::pow(" }, { "pow(", "std::pow(" },
{ "fabs(", "std::abs(" }, { "fabs(", "std::abs(" },
{ "log(", "std::log(" },
{ "sqr(", "Sqr(" }, { "sqr(", "Sqr(" },