2014-07-08 03:11:14 -04:00
|
|
|
#include "FractoriumPch.h"
|
|
|
|
#include "Fractorium.h"
|
|
|
|
|
2016-01-16 14:51:29 -05:00
|
|
|
#define XAOS_PREC 6
|
|
|
|
|
2014-07-08 03:11:14 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Initialize the xforms xaos UI.
|
|
|
|
/// </summary>
|
2015-04-27 01:11:56 -04:00
|
|
|
void Fractorium::InitXaosUI()
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2015-05-30 00:08:44 -04:00
|
|
|
int spinHeight = 20;
|
|
|
|
ui.XaosTableView->verticalHeader()->setSectionsClickable(true);
|
|
|
|
ui.XaosTableView->horizontalHeader()->setSectionsClickable(true);
|
|
|
|
m_XaosSpinBox = new DoubleSpinBox(nullptr, spinHeight, 0.1);
|
|
|
|
m_XaosSpinBox->DoubleClick(true);
|
|
|
|
m_XaosSpinBox->DoubleClickZero(1);
|
|
|
|
m_XaosSpinBox->DoubleClickNonZero(0);
|
2016-01-16 14:51:29 -05:00
|
|
|
m_XaosSpinBox->setDecimals(XAOS_PREC);
|
2015-10-27 00:31:35 -04:00
|
|
|
m_XaosSpinBox->setObjectName("XaosSpinBox");
|
2015-05-30 00:08:44 -04:00
|
|
|
m_XaosTableModel = nullptr;
|
|
|
|
m_XaosTableItemDelegate = new DoubleSpinBoxTableItemDelegate(m_XaosSpinBox, this);
|
|
|
|
connect(m_XaosSpinBox, SIGNAL(valueChanged(double)), this, SLOT(OnXaosChanged(double)), Qt::QueuedConnection);
|
2014-07-08 03:11:14 -04:00
|
|
|
connect(ui.ClearXaosButton, SIGNAL(clicked(bool)), this, SLOT(OnClearXaosButtonClicked(bool)), Qt::QueuedConnection);
|
2014-10-15 23:09:44 -04:00
|
|
|
connect(ui.RandomXaosButton, SIGNAL(clicked(bool)), this, SLOT(OnRandomXaosButtonClicked(bool)), Qt::QueuedConnection);
|
2015-05-30 00:08:44 -04:00
|
|
|
connect(ui.XaosTableView->verticalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(OnXaosRowDoubleClicked(int)), Qt::QueuedConnection);
|
|
|
|
connect(ui.XaosTableView->horizontalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(OnXaosColDoubleClicked(int)), Qt::QueuedConnection);
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2015-04-08 21:23:29 -04:00
|
|
|
/// Fill the xaos table with the values from the ember.
|
2014-07-08 03:11:14 -04:00
|
|
|
/// </summary>
|
|
|
|
template <typename T>
|
2015-04-08 21:23:29 -04:00
|
|
|
void FractoriumEmberController<T>::FillXaos()
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
for (int i = 0, count = int(XformCount()); i < count; i++)
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2015-05-30 00:08:44 -04:00
|
|
|
if (auto xform = m_Ember.GetXform(i))
|
|
|
|
{
|
|
|
|
for (int j = 0; j < count; j++)
|
|
|
|
{
|
|
|
|
QModelIndex index = m_Fractorium->m_XaosTableModel->index(i, j, QModelIndex());
|
|
|
|
m_Fractorium->m_XaosTableModel->setData(index, xform->Xaos(j));
|
|
|
|
}
|
|
|
|
}
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
2015-09-14 23:53:19 -04:00
|
|
|
|
|
|
|
m_Fractorium->ui.XaosTableView->resizeRowsToContents();
|
|
|
|
m_Fractorium->ui.XaosTableView->resizeColumnsToContents();
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set the xaos value.
|
|
|
|
/// Called when any xaos spinner is changed.
|
2015-05-30 00:08:44 -04:00
|
|
|
/// It actually gets called multiple times as the user clicks around the
|
|
|
|
/// xaos table due to how QTableView passes events to and from its model.
|
|
|
|
/// To filter out spurrious events, the value is checked against the existing
|
|
|
|
/// xaos value.
|
2014-07-08 03:11:14 -04:00
|
|
|
/// Resets the rendering process.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender">The DoubleSpinBox that triggered this event</param>
|
|
|
|
template <typename T>
|
2015-05-30 00:08:44 -04:00
|
|
|
void FractoriumEmberController<T>::XaosChanged(int x, int y, double val)
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2016-01-16 14:51:29 -05:00
|
|
|
auto newVal = TruncPrecision(val, XAOS_PREC);//Sometimes 0 comes in as a very small number, so round.
|
|
|
|
|
|
|
|
if (auto xform = m_Ember.GetXform(x))
|
2016-02-12 00:38:21 -05:00
|
|
|
if (!IsClose<T>(newVal, xform->Xaos(y), T(1e-7)))
|
2016-01-16 14:51:29 -05:00
|
|
|
Update([&] { xform->SetXaos(y, newVal); });
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Fractorium::OnXaosChanged(double d)
|
|
|
|
{
|
--User changes
-Add a palette editor.
-Add support for reading .ugr/.gradient/.gradients palette files.
-Allow toggling on spinners whose minimum value is not zero.
-Allow toggling display of image, affines and grid.
-Add new variations: cylinder2, circlesplit, tile_log, truchet_fill, waves2_radial.
--Bug fixes
-cpow2 was wrong.
-Palettes with rapid changes in color would produce slightly different outputs from Apo/Chaotica. This was due to a long standing bug from flam3.
-Use exec() on Apple and show() on all other OSes for dialog boxes.
-Trying to render a sequence with no frames would crash.
-Selecting multiple xforms and rotating them would produce the wrong rotation.
-Better handling when parsing flames using different encoding, such as unicode and UTF-8.
-Switching between SP/DP didn't reselect the selected flame in the Library tab.
--Code changes
-Make all types concerning palettes be floats, including PaletteTableWidgetItem.
-PaletteTableWidgetItem is no longer templated because all palettes are float.
-Include the source colors for user created gradients.
-Change parallel_for() calls to work with very old versions of TBB which are lingering on some systems.
-Split conditional out of accumulation loop on the CPU for better performance.
-Vectorize summing when doing density filter for better performance.
-Make all usage of palettes be of type float, double is pointless.
-Allow palettes to reside in multiple folders, while ensuring only one of each name is added.
-Refactor some palette path searching code.
-Make ReadFile() throw and catch an exception if the file operation fails.
-A little extra safety in foci and foci3D with a call to Zeps().
-Cast to (real_t) in the OpenCL string for the w variation, which was having trouble compiling on Mac.
-Fixing missing comma between paths in InitPaletteList().
-Move Xml and PaletteList classes into cpp to shorten build times when working on them.
-Remove default param values for IterOpenCLKernelCreator<T>::SharedDataIndexDefines in cpp file.
-Change more NULL to nullptr.
2017-02-26 03:02:21 -05:00
|
|
|
if (auto senderSpinBox = qobject_cast<DoubleSpinBox*>(sender()))
|
2015-05-30 00:08:44 -04:00
|
|
|
{
|
|
|
|
auto p = senderSpinBox->property("tableindex").toPoint();
|
|
|
|
m_Controller->XaosChanged(p.x(), p.y(), d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fractorium::OnXaosTableModelDataChanged(const QModelIndex& indexA, const QModelIndex& indexB)
|
|
|
|
{
|
|
|
|
m_Controller->XaosChanged(indexA.row(), indexA.column(), indexA.data().toDouble());
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2015-04-08 21:23:29 -04:00
|
|
|
/// Clear xaos table, recreate all spinners based on the xaos used in the current ember.
|
2014-07-08 03:11:14 -04:00
|
|
|
/// </summary>
|
|
|
|
void Fractorium::FillXaosTable()
|
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
int count = int(m_Controller->XformCount());
|
2015-05-30 00:08:44 -04:00
|
|
|
QStringList hl, vl;
|
|
|
|
auto oldModel = m_XaosTableModel;
|
|
|
|
hl.reserve(count);
|
|
|
|
vl.reserve(count);
|
|
|
|
m_XaosTableModel = new QStandardItemModel(count, count, this);
|
|
|
|
connect(m_XaosTableModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(OnXaosTableModelDataChanged(QModelIndex, QModelIndex)));
|
|
|
|
ui.XaosTableView->blockSignals(true);
|
2015-04-08 21:23:29 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2015-05-30 00:08:44 -04:00
|
|
|
auto s = QString::number(i + 1);
|
|
|
|
hl.push_back("F" + s);
|
|
|
|
vl.push_back("T" + s);
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
2014-07-28 01:25:38 -04:00
|
|
|
|
2015-05-30 00:08:44 -04:00
|
|
|
m_XaosTableModel->setHorizontalHeaderLabels(hl);
|
|
|
|
m_XaosTableModel->setVerticalHeaderLabels(vl);
|
|
|
|
ui.XaosTableView->setModel(m_XaosTableModel);
|
|
|
|
ui.XaosTableView->setItemDelegate(m_XaosTableItemDelegate);
|
|
|
|
SetTabOrder(this, ui.ClearXaosButton, ui.RandomXaosButton);
|
2015-09-27 15:06:47 -04:00
|
|
|
m_Controller->FillXaos();
|
2015-05-30 00:08:44 -04:00
|
|
|
ui.XaosTableView->blockSignals(false);
|
2016-01-16 14:51:29 -05:00
|
|
|
|
2015-05-30 00:08:44 -04:00
|
|
|
if (oldModel)
|
|
|
|
delete oldModel;
|
2015-10-27 00:31:35 -04:00
|
|
|
|
|
|
|
//Needed to get the dark stylesheet to correctly color the top left corner button.
|
|
|
|
auto widgetList = ui.XaosTableView->findChildren<QAbstractButton*>();
|
|
|
|
|
|
|
|
for (auto& it : widgetList)
|
|
|
|
it->setEnabled(true);
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Clear all xaos from the current ember.
|
|
|
|
/// </summary>
|
|
|
|
template <typename T>
|
|
|
|
void FractoriumEmberController<T>::ClearXaos()
|
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
Update([&] { m_Ember.ClearXaos(); });
|
|
|
|
FillXaos();
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
2014-10-15 23:09:44 -04:00
|
|
|
void Fractorium::OnClearXaosButtonClicked(bool checked) { m_Controller->ClearXaos(); }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set all xaos values to random numbers.
|
|
|
|
/// There is a 50% chance they're set to 0 or 1, and
|
|
|
|
/// 50% that they're 0-3.
|
2014-10-27 17:21:06 -04:00
|
|
|
/// Resets the rendering process.
|
2014-10-15 23:09:44 -04:00
|
|
|
/// </summary>
|
|
|
|
template <typename T>
|
|
|
|
void FractoriumEmberController<T>::RandomXaos()
|
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
Update([&]
|
2014-10-15 23:09:44 -04:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < m_Ember.XformCount(); i++)
|
|
|
|
{
|
2016-02-20 21:44:52 -05:00
|
|
|
if (auto xform = m_Ember.GetXform(i))
|
2014-10-15 23:09:44 -04:00
|
|
|
{
|
|
|
|
for (size_t j = 0; j < m_Ember.XformCount(); j++)
|
|
|
|
{
|
|
|
|
if (m_Rand.RandBit())
|
2015-04-08 21:23:29 -04:00
|
|
|
xform->SetXaos(j, T(m_Rand.RandBit()));
|
2014-10-15 23:09:44 -04:00
|
|
|
else
|
2015-04-08 21:23:29 -04:00
|
|
|
xform->SetXaos(j, m_Rand.Frand<T>(0, 3));
|
2014-10-15 23:09:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-04-08 21:23:29 -04:00
|
|
|
FillXaos();
|
2014-10-15 23:09:44 -04:00
|
|
|
}
|
|
|
|
|
2014-12-11 00:50:15 -05:00
|
|
|
void Fractorium::OnRandomXaosButtonClicked(bool checked) { m_Controller->RandomXaos(); }
|
|
|
|
|
2015-05-03 20:13:14 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Toggle all xaos values in one row.
|
|
|
|
/// Resets the rendering process.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="logicalIndex">The index of the row that was double clicked</param>
|
|
|
|
void Fractorium::OnXaosRowDoubleClicked(int logicalIndex)
|
|
|
|
{
|
2015-05-30 00:08:44 -04:00
|
|
|
ToggleTableRow(ui.XaosTableView, logicalIndex);
|
2015-09-14 23:53:19 -04:00
|
|
|
ui.XaosTableView->resizeRowsToContents();
|
|
|
|
ui.XaosTableView->resizeColumnsToContents();
|
2015-05-03 20:13:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Toggle all xaos values in one column.
|
|
|
|
/// Resets the rendering process.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="logicalIndex">The index of the column that was double clicked</param>
|
|
|
|
void Fractorium::OnXaosColDoubleClicked(int logicalIndex)
|
|
|
|
{
|
2015-05-30 00:08:44 -04:00
|
|
|
ToggleTableCol(ui.XaosTableView, logicalIndex);
|
2015-09-14 23:53:19 -04:00
|
|
|
ui.XaosTableView->resizeRowsToContents();
|
|
|
|
ui.XaosTableView->resizeColumnsToContents();
|
2015-05-03 20:13:14 -04:00
|
|
|
}
|
|
|
|
|
2014-12-11 00:50:15 -05:00
|
|
|
template class FractoriumEmberController<float>;
|
|
|
|
|
|
|
|
#ifdef DO_DOUBLE
|
2016-01-16 14:51:29 -05:00
|
|
|
template class FractoriumEmberController<double>;
|
2014-12-11 00:50:15 -05:00
|
|
|
#endif
|