Commit 6d1a2ce6 authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'schnapps_update' into 'develop'

Schnapps update

See merge request !2
parents 208dd6f9 fd256f83
......@@ -2,4 +2,5 @@
CMakeLists.txt.user
bin/
ThirdParty/bin/
SCHNApps/bin
\ No newline at end of file
SCHNApps/bin/
windows_dependencies/
......@@ -38,16 +38,14 @@ MapHandlerGen* Surface_Import_Plugin::importMeshFromFile(const QString& nameOfFi
QFileInfo fi(fileName);
if(fi.exists())
{
pythonRecording("importMeshFromFile", fi.baseName(), fileName);
MapHandlerGen* mhg = m_schnapps->addMap(fi.baseName(), 2);
MapHandlerGen* mhg = m_schnapps->addMap(SCHNApps::forceASCII(fi.baseName()), 2);
if(mhg)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
PFP2::MAP* map = mh->getMap();
std::vector<std::string> attrNames;
Algo::Surface::Import::importMesh<PFP2>(*map, fileName.toStdString(), attrNames);
Algo::Surface::Import::importMesh<PFP2>(*map, SCHNApps::niceStdString(fileName), attrNames);
for (unsigned int orbit = VERTEX; orbit <= VOLUME; orbit++)
{
......@@ -60,6 +58,7 @@ MapHandlerGen* Surface_Import_Plugin::importMeshFromFile(const QString& nameOfFi
mhg->registerAttribute(orbit, QString::fromStdString(names[i]), QString::fromStdString(types[i]));
}
}
pythonRecording("importMeshFromFile", mhg->getName(), fileName);
return mhg;
}
else
......@@ -84,9 +83,7 @@ MapHandlerGen* Surface_Import_Plugin::importImageFromFile(const QString& nameOfF
QFileInfo fi(fileName);
if(fi.exists())
{
pythonRecording("importImageFromFile", fi.baseName(), fileName);
MapHandlerGen* mhg = m_schnapps->addMap(fi.baseName(), 2);
MapHandlerGen* mhg = m_schnapps->addMap(SCHNApps::forceASCII(fi.baseName()), 2);
if(mhg)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
......@@ -123,6 +120,7 @@ MapHandlerGen* Surface_Import_Plugin::importImageFromFile(const QString& nameOfF
mh->registerAttribute(color);
}
pythonRecording("importImageFromFile", mhg->getName(), fileName);
return mhg;
}
else
......
......@@ -14,10 +14,30 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="0" colspan="2">
<widget class="QPushButton" name="button_clear">
<item row="9" column="0" colspan="2">
<widget class="QSlider" name="slider_verticesScaleFactor">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Clear current selection</string>
<string>Normal :</string>
</property>
</widget>
</item>
......@@ -30,10 +50,10 @@
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<item row="6" column="0" colspan="2">
<widget class="QPushButton" name="button_clear">
<property name="text">
<string>Normal :</string>
<string>Clear current selection</string>
</property>
</widget>
</item>
......@@ -62,40 +82,6 @@
</item>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QSlider" name="slider_verticesScaleFactor">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combo_positionAttribute">
<property name="sizePolicy">
......@@ -111,10 +97,10 @@
</item>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Selected vertice size</string>
<item row="5" column="0" colspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
......@@ -125,14 +111,35 @@
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Selected vertice size</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Selected vertices color</string>
</property>
</widget>
</item>
<item row="14" column="1">
<item row="7" column="0" colspan="2">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="15" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -145,13 +152,35 @@
</property>
</spacer>
</item>
<item row="10" column="0" colspan="2">
<item row="11" column="0" colspan="2">
<widget class="ColorComboBox" name="combo_color"/>
</item>
<item row="6" column="0" colspan="2">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="spin_angle_radius">
<property name="toolTip">
<string/>
</property>
<property name="statusTip">
<string/>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_angle_radius">
<property name="text">
<string/>
</property>
</widget>
</item>
......
......@@ -24,7 +24,7 @@ Surface_Selection_Plugin::Surface_Selection_Plugin() :
m_selectedFaces_dirty(false),
m_selectionRadiusBase(1),
m_selectionRadiusCoeff(1),
m_normalAngleThreshold(10)
m_normalAngleThreshold(float(10*M_PI/180))
{}
bool Surface_Selection_Plugin::enable()
......@@ -89,8 +89,11 @@ void Surface_Selection_Plugin::disable()
delete m_selectionSphereVBO;
disconnect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
//disconnect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
//disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(selectedCellSelectorChanged(CellSelectorGen*)), this, SLOT(updateSelectedCellsRendering()));
}
void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
......@@ -115,13 +118,11 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
{
if (m_selectedVertices_dirty)
updateSelectedCellsRendering();
m_pointSprite->setAttributePosition(m_selectedVerticesVBO);
const QColor& col = p.color;
m_pointSprite->setColor(Geom::Vec4f(col.redF(), col.greenF(), col.blueF(), 0.0f));
m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
m_pointSprite->setSize(p.basePSradius*p.verticesScaleFactor);
m_pointSprite->enableVertexAttribs();
glDrawArrays(GL_POINTS, 0, selector->getNbSelectedCells());
m_pointSprite->disableVertexAttribs();
......@@ -132,11 +133,9 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
std::vector<PFP2::VEC3> selectionPoint;
selectionPoint.push_back(p.positionAttribute[m_selectingVertex]);
m_selectionSphereVBO->updateData(selectionPoint);
m_pointSprite->setAttributePosition(m_selectionSphereVBO);
m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 0.5f));
m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
switch(p.selectionMethod)
{
case NormalAngle :
......@@ -147,7 +146,6 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
m_pointSprite->setSize(m_selectionRadiusBase * m_selectionRadiusCoeff);
break;
}
m_pointSprite->enableVertexAttribs();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
......@@ -502,14 +500,16 @@ void Surface_Selection_Plugin::wheelEvent(View* view, QWheelEvent* event)
else
m_selectionRadiusCoeff *= 1.1f;
view->updateGL();
m_dockTab->spin_angle_radius->setValue(m_selectionRadiusBase * m_selectionRadiusCoeff);
break;
}
case NormalAngle : {
if(event->delta() > 0)
m_normalAngleThreshold *= 0.9f;
m_normalAngleThreshold -= CGoGN::PFP_SCHNAPPS::REAL(M_PI / 180);
else
m_normalAngleThreshold *= 1.1f;
m_normalAngleThreshold += CGoGN::PFP_SCHNAPPS::REAL(M_PI / 180);
// view->displayMessage(QString("Angle threshold : ") + m_normalAngleThreshold);
m_dockTab->spin_angle_radius->setValue(m_normalAngleThreshold/M_PI*180);
break;
}
}
......@@ -573,7 +573,6 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering()
m_selectedEdgesDrawer->newList(GL_COMPILE);
m_selectedEdgesDrawer->lineWidth(3.0f);
// m_selectedEdgesDrawer->color3f(1.0f, 0.0f, 0.0f);
m_selectedEdgesDrawer->color3f(p.color.redF(), p.color.greenF(), p.color.blueF());
m_selectedEdgesDrawer->begin(GL_LINES);
for(std::vector<Edge>::const_iterator e = selectedCells.begin(); e != selectedCells.end(); ++e)
......
......@@ -43,6 +43,7 @@ void Surface_Selection_DockTab::positionAttributeChanged(int index)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(map);
m_plugin->h_parameterSet[map].positionAttribute = mh->getAttribute<PFP2::VEC3, VERTEX>(combo_positionAttribute->currentText());
m_plugin->updateSelectedCellsRendering();
m_plugin->pythonRecording("changePositionAttribute", "", map->getName(), combo_positionAttribute->currentText());
}
}
......@@ -57,6 +58,7 @@ void Surface_Selection_DockTab::normalAttributeChanged(int index)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(map);
m_plugin->h_parameterSet[map].normalAttribute = mh->getAttribute<PFP2::VEC3, VERTEX>(combo_normalAttribute->currentText());
m_plugin->updateSelectedCellsRendering();
m_plugin->pythonRecording("changeNormalAttribute", "", map->getName(), combo_normalAttribute->currentText());
}
}
......@@ -72,6 +74,26 @@ void Surface_Selection_DockTab::selectionMethodChanged(int index)
m_plugin->h_parameterSet[map].selectionMethod = SelectionMethod(index);
m_plugin->pythonRecording("changeSelectionMethod", "", map->getName(), index);
}
switch (index)
{
case 0:
this->spin_angle_radius->setHidden(true);
this->label_angle_radius->setText(QString());
break;
case 1:
this->spin_angle_radius->setHidden(false);
this->spin_angle_radius->setValue(m_plugin->m_selectionRadiusBase * m_plugin->m_selectionRadiusCoeff);
this->label_angle_radius->setText(QString("Radius:"));
break;
case 2:
this->spin_angle_radius->setHidden(false);
this->spin_angle_radius->setValue(m_plugin->m_normalAngleThreshold / M_PI * 180);
this->label_angle_radius->setText(QString("Angle:"));
break;
default:
break;
}
}
}
......@@ -204,6 +226,27 @@ void Surface_Selection_DockTab::updateMapParameters()
combo_color->setColor(p.color);
slider_verticesScaleFactor->setValue(int(50.0*p.verticesScaleFactor));
switch (p.selectionMethod)
{
case 0:
this->spin_angle_radius->setHidden(true);
this->label_angle_radius->setText(QString());
break;
case 1:
this->spin_angle_radius->setHidden(false);
this->spin_angle_radius->setValue(m_plugin->m_selectionRadiusBase * m_plugin->m_selectionRadiusCoeff);
this->label_angle_radius->setText(QString("Radius:"));
break;
case 2:
this->spin_angle_radius->setHidden(false);
this->spin_angle_radius->setValue(m_plugin->m_normalAngleThreshold / M_PI * 180);
this->label_angle_radius->setText(QString("Angle:"));
break;
default:
break;
}
}
b_updatingUI = false;
......
......@@ -106,6 +106,12 @@ public slots:
*/
bool isBBshown() const;
/**
* @brief [PYTHON] set color for drawing BB the bounding-box
* @param color color name (red,green,...) or color format #rrggbb
*/
void setBBColor(const QString& color);
/**
* @brief [PYTHON] choose the vertex attribute used to compute the bounding-box
* @param name name of attribute
......@@ -347,7 +353,23 @@ public slots:
* @param sz scaling z factor
*/
void setScaling(float sx, float sy, float sz);
/**
* @brief [PYTHON] Save the frame into a string
* @return the storage string
*/
QString frameToString();
/**
* @brief [PYTHON] restore frame from string storage
* @param frame the string with frame info
*/
void frameFromString(QString frame);
/**
* @brief reset the frame manipulator to its initial position
*/
void frameReset();
/*********************************************************
* SIGNALS
......@@ -385,6 +407,7 @@ protected:
AttributeMultiVectorGen* m_bbVertexAttribute;
float m_bbDiagSize;
Utils::Drawer* m_bbDrawer;
glm::vec3 m_bbColor;
Algo::Render::GL2::MapRender* m_render;
Algo::Render::GL2::TopoRender* m_topoRender;
......@@ -409,11 +432,7 @@ public:
MapHandlerGen(name, s, map)
{}
~MapHandler()
{
if (m_map)
delete m_map;
}
~MapHandler();
inline MAP* getMap() { return static_cast<MAP*>(m_map); }
......
......@@ -9,6 +9,8 @@ namespace CGoGN
namespace SCHNApps
{
inline void MapHandlerGen::registerAttribute(const AttributeHandlerGen& ah)
{
m_attribs[ah.getOrbit()].insert(QString::fromStdString(ah.name()), QString::fromStdString(ah.typeName()));
......@@ -31,6 +33,29 @@ inline QString MapHandlerGen::getAttributeTypeName(unsigned int orbit, const QSt
template <typename PFP>
MapHandler<PFP>::~MapHandler()
{
// clean the cell selector
for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{
foreach(CellSelectorGen* cs, m_cellSelectors[orbit])
{
if (cs)
{
emit(cellSelectorRemoved(orbit, cs->getName()));
disconnect(cs, SIGNAL(selectedCellsChanged()), this, SLOT(selectedCellsChanged()));
delete cs;
}
}
m_cellSelectors[orbit].clear();
}
if (m_map)
delete m_map;
}
template <typename PFP>
unsigned int MapHandler<PFP>::getNbDarts()
{
......@@ -132,7 +157,7 @@ void MapHandler<PFP>::updateBBDrawer()
bbmax += Geom::Vec3f(shift, shift, shift);
m_bbDrawer->newList(GL_COMPILE);
m_bbDrawer->color3f(0.0f, 1.0f, 0.0f);
m_bbDrawer->color3f(m_bbColor[0], m_bbColor[1], m_bbColor[2]);
m_bbDrawer->lineWidth(2.0f);
// m_bbDrawer->lineWidth(shift);
m_bbDrawer->begin(GL_LINE_LOOP);
......
......@@ -89,9 +89,21 @@ inline T pyR_stringify(T v)
template <>
inline QString pyR_stringify(QString v)
{
return "\"" + v + "\"";
}
// test if v containe non ascii char
bool needDecode = false;
int i = 0;
while (!needDecode && (i < v.size()))
{
if (v[i].unicode()>127)
needDecode = true;
++i;
}
if (needDecode)
return "\"" + v + "\".decode('latin-1')";
else
return "\"" + v + "\"";
}
template <typename T1>
......
......@@ -316,10 +316,29 @@ public slots:
void showHidePluginDock();
void showHidePythonDock();
/**
* @brief [PYTHON] set if control dock is floating or docked
* @param 1: floating / 0: docked
*/
void setFloatingControlDock(bool f);
/**
* @brief [PYTHON] set if plugin dock is floating or docked
* @param 1: floating / 0: docked
*/
void setFloatingPluginDock(bool f);
/**
* @brief [PYTHON] set if python dock is floating or docked
* @param 1: floating / 0: docked
*/
void setFloatingPythonDock(bool f);
/**
* @brief [PYTHON] Load a python script store in a file.
* @param fileName the filename with absolute path or relative to path set with setPythonPath
* #return true if reading file ok
* @return true if reading file ok
*/
bool loadPythonScriptFromFile(const QString& fileName);
......@@ -396,6 +415,12 @@ public:
/// replace \ by / in file path for window
static QString noBackSlash(const QString& name);
/// transform QString in std::string with
static std::string niceStdString(const QString& qstr);
/// force QString contain to be ascii (non ascii char are replaced by '_')
static QString forceASCII(const QString& qstr);
signals:
void cameraAdded(Camera* camera);
......
......@@ -324,9 +324,31 @@ void ControlDock_MapTab::mapRemoved(MapHandlerGen* m)
if(!items.empty())
{
b_updatingUI = true;
delete items[0];
if (m_schnapps->getSelectedMap() == m)
{
std::cout << "Unselecting" << std::endl;
m_selectedSelector[DART] = NULL;
foreach(QListWidgetItem* item, list_dartSelectors->selectedItems())
item->setSelected(false);
m_selectedSelector[VERTEX] = NULL;
foreach(QListWidgetItem* item, list_vertexSelectors->selectedItems())
item->setSelected(false);
m_selectedSelector[EDGE] = NULL;
foreach(QListWidgetItem* item, list_edgeSelectors->selectedItems())
item->setSelected(false);
m_selectedSelector[FACE] = NULL;
foreach(QListWidgetItem* item, list_faceSelectors->selectedItems())
item->setSelected(false);
m_selectedSelector[VOLUME] = NULL;
foreach(QListWidgetItem* item, list_volumeSelectors->selectedItems())
item->setSelected(false);
}
b_updatingUI = false;
}
}
......
......@@ -16,6 +16,7 @@ MapHandlerGen::MapHandlerGen(const QString& name, SCHNApps* s, GenericMap* map)
m_transfoMatrixInv(1.0f),
m_bbVertexAttribute(NULL),
m_bbDrawer(NULL),
m_bbColor(0,1,0),
m_render(NULL),
m_topoRender(NULL)
{
......@@ -108,6 +109,16 @@ bool MapHandlerGen::isBBshown() const
return m_showBB;
}
void MapHandlerGen::setBBColor(const QString& color)
{
QColor col(color);
m_bbColor[0] = col.redF();
m_bbColor[1] = col.greenF();
m_bbColor[2] = col.blueF();
updateBB();
}
void MapHandlerGen::setBBVertexAttribute(const QString& name)
{
m_bbVertexAttribute = m_map->getAttributeVectorGen(VERTEX, name.toStdString());
......@@ -422,6 +433,45 @@ void MapHandlerGen::setScaling(float sx, float sy, float sz)
QString MapHandlerGen::frameToString()
{
QString res;
QTextStream str(&res);
const GLdouble* mat = m_frame->matrix();
for (int i = 0; i < 16; ++i)
str << mat[i] << " ";
return res;
}
void MapHandlerGen::frameFromString(QString frame)
{
QTextStream str(&frame);
GLdouble mat[16];
for (int i = 0; i < 16; ++i)
str >> mat[i];
m_frame->setFromMatrix(mat);
frameModified();
}
void MapHandlerGen::frameReset()
{
GLdouble mat[16];
// Identity
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j)
if (i==j)
mat[i*4+j] = 1;
else
mat[i*4+j] = 0;
m_frame->setFromMatrix(mat);
frameModified();
}
......
......@@ -727,25 +727,33 @@ MapHandlerGen* SCHNApps::duplicateMap(const QString& name, bool properties)
MapHandlerGen* SCHNApps::addMap(const QString& name, unsigned int dim)
{
QString finalName = name;
if (m_maps.contains(name))
return NULL;
{
int i = 1;
do
{
finalName = name + QString("_") + QString::number(i);
++i;
} while (m_maps.contains(finalName));
}
MapHandlerGen* mh = NULL;
switch(dim)
{
case 2 : {
PFP2::MAP* map = new PFP2::MAP();
mh = new MapHandler<PFP2>(name, this, map);
mh = new MapHandler<PFP2>(finalName, this, map);
break;
}
case 3 : {
PFP3::MAP* map = new PFP3::MAP();
mh = new MapHandler<PFP3>(name, this, map);
mh = new MapHandler<PFP3>(finalName, this, map);
break;
}
}
m_maps.insert(name, mh);
m_maps.insert(finalName, mh);
DEBUG_EMIT("mapAdded");
emit(mapAdded(mh));
......@@ -1000,6 +1008,22 @@ void SCHNApps::showHidePythonDock()
}
void SCHNApps::setFloatingControlDock(bool f)
{
m_controlDock->setFloating(f);
}
void SCHNApps::setFloatingPluginDock(bool f)
{
m_pluginDock->setFloating(f);
}
void SCHNApps::setFloatingPythonDock(bool f)
{