Commit 79056382 authored by Pierre Kraemer's avatar Pierre Kraemer

Full collapse decimation in Radiance plugin

parent 4144a1be
......@@ -14,7 +14,14 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="1">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item row="5" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -27,10 +34,10 @@
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="button_decimate">
<property name="text">
<string>Position :</string>
<string>Decimate</string>
</property>
</widget>
</item>
......@@ -41,8 +48,8 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combo_positionVBO">
<item row="1" column="1">
<widget class="QComboBox" name="combo_normalVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -56,8 +63,21 @@
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="combo_normalVBO">
<item row="2" column="0" colspan="2">
<widget class="QSlider" name="slider_decimationGoal">
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combo_positionVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -72,22 +92,9 @@
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="button_decimate">
<widget class="QCheckBox" name="checkbox_halfCollapse">
<property name="text">
<string>Decimate</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QSlider" name="slider_decimationGoal">
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<string>Half Collapse</string>
</property>
</widget>
</item>
......
......@@ -42,9 +42,9 @@ struct MapParameters
DartAttribute<PFP2::REAL, PFP2::MAP> halfedgeError;
Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, PFP2::VEC3>* positionApproximator;
Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, PFP2::VEC3>* normalApproximator;
Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3> >* radianceApproximator;
Algo::Surface::Decimation::ApproximatorGen<PFP2>* positionApproximator;
Algo::Surface::Decimation::ApproximatorGen<PFP2>* normalApproximator;
Algo::Surface::Decimation::ApproximatorGen<PFP2>* radianceApproximator;
Algo::Surface::Decimation::Selector<PFP2>* selector;
};
......@@ -103,10 +103,15 @@ public slots:
const QString& positionAttributeName,
const QString& normalAttributeName,
float decimationGoal,
bool exportMeshes = false,
unsigned int nbExports = 0
bool halfCollapse = false,
bool exportMeshes = false
);
void exportPLY(
const QString& mapName,
const QString& positionAttributeName,
const QString& normalAttributeName,
const QString& filename
);
void exportPLY(const QString& mapName, const QString& positionAttributeName, const QString& normalAttributeName, const QString& filename);
protected:
MapHandlerGen* currentlyDecimatedMap() { return m_currentlyDecimatedMap; }
......
......@@ -2,8 +2,7 @@
#include "meshTableSurfaceRadiance.h"
#include "halfEdgeSelectorRadiance.h"
#include "Algo/Decimation/halfEdgeSelector.h"
#include "edgeSelectorRadiance.h"
#include "mapHandler.h"
#include "camera.h"
......@@ -281,7 +280,7 @@ MapHandlerGen* Surface_Radiance_Plugin::importFromFile(const QString& fileName)
return NULL;
}
void Surface_Radiance_Plugin::decimate(const QString& mapName, const QString& positionAttributeName, const QString& normalAttributeName, float decimationGoal, bool exportMeshes, unsigned int nbExports)
void Surface_Radiance_Plugin::decimate(const QString& mapName, const QString& positionAttributeName, const QString& normalAttributeName, float decimationGoal, bool halfCollapse, bool exportMeshes)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName));
if(mh == NULL)
......@@ -301,25 +300,78 @@ void Surface_Radiance_Plugin::decimate(const QString& mapName, const QString& po
MapParameters& mapParams = h_mapParameterSet[mh];
if (mapParams.positionApproximator == NULL)
if (halfCollapse)
{
mapParams.positionApproximator = new Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, PFP2::VEC3>(*map, position);
}
if (mapParams.positionApproximator == NULL)
{
mapParams.positionApproximator = new Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, PFP2::VEC3>(*map, position);
}
if (mapParams.normalApproximator == NULL)
{
mapParams.normalApproximator = new Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, PFP2::VEC3>(*map, normal);
}
if (mapParams.normalApproximator == NULL)
{
mapParams.normalApproximator = new Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, PFP2::VEC3>(*map, normal);
}
if (mapParams.radianceApproximator == NULL)
{
mapParams.radianceApproximator = new Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3> >(*map, mapParams.radiance);
}
if (mapParams.radianceApproximator == NULL)
{
mapParams.radianceApproximator = new Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3> >(*map, mapParams.radiance);
}
if (mapParams.selector == NULL)
if (mapParams.selector == NULL)
{
mapParams.selector = new HalfEdgeSelector_Radiance<PFP2>(
*map,
position,
normal,
mapParams.radiance,
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, DART>*)(mapParams.positionApproximator),
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, DART>*)(mapParams.normalApproximator),
*(Algo::Surface::Decimation::Approximator<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>, DART>*)(mapParams.radianceApproximator)
);
}
}
else
{
mapParams.selector = new HalfEdgeSelector_Radiance<PFP2>(*map, position, normal, mapParams.radiance, *mapParams.positionApproximator, *mapParams.normalApproximator, *mapParams.radianceApproximator);
// mapParams.selector = new Algo::Surface::Decimation::HalfEdgeSelector_QEMml<PFP2>(*map, position, *mapParams.positionApproximator);
if (mapParams.positionApproximator == NULL)
{
mapParams.positionApproximator = new Algo::Surface::Decimation::Approximator_QEM<PFP2>(*map, position);
}
if (mapParams.normalApproximator == NULL)
{
mapParams.normalApproximator =
new Algo::Surface::Decimation::Approximator_InterpolateAlongEdge<PFP2, PFP2::VEC3>(
*map,
normal,
position,
((Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator))->getApproximationResultAttribute()
);
}
if (mapParams.radianceApproximator == NULL)
{
mapParams.radianceApproximator =
new Algo::Surface::Decimation::Approximator_InterpolateAlongEdge<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3> >(
*map,
mapParams.radiance,
position,
((Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator))->getApproximationResultAttribute()
);
}
if (mapParams.selector == NULL)
{
mapParams.selector =
new EdgeSelector_Radiance<PFP2>(
*map,
position,
normal,
mapParams.radiance,
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator),
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.normalApproximator),
*(Algo::Surface::Decimation::Approximator<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>, EDGE>*)(mapParams.radianceApproximator)
);
}
}
std::vector<Algo::Surface::Decimation::ApproximatorGen<PFP2>*> approximators;
......@@ -330,13 +382,23 @@ void Surface_Radiance_Plugin::decimate(const QString& mapName, const QString& po
exportNbVert.clear();
if (exportMeshes)
{
float decimationStep = (1.0 - decimationGoal) / nbExports;
for (unsigned int i = 1; i <= nbExports; ++i)
unsigned int goalNbV = decimationGoal * nbVertices;
unsigned int curNbV = nbVertices / 2;
while (curNbV > goalNbV)
{
exportNbVert.push_back( (1.0 - (i * decimationStep)) * nbVertices );
exportNbVert.push_back(curNbV);
curNbV /= 2;
}
exportNbVert.push_back(goalNbV);
nextExportIndex = 0;
}
std::cout << "nb vert -> " << nbVertices << std::endl;
for (unsigned int v : exportNbVert)
{
std::cout << v << std::endl;
}
m_currentlyDecimatedMap = mh;
Algo::Surface::Decimation::decimate<PFP2>(*map, mapParams.selector, approximators, decimationGoal * nbVertices, true, NULL, (void (*)(void*, const void*))(Surface_Radiance_Plugin::checkNbVerticesAndExport), (void*)(this));
m_currentlyDecimatedMap = NULL;
......
......@@ -52,7 +52,13 @@ void Surface_Radiance_DockTab::normalVBOChanged(int index)
void Surface_Radiance_DockTab::decimateClicked()
{
m_plugin->decimate(m_schnapps->getSelectedMap()->getName(), combo_positionVBO->currentText(), combo_normalVBO->currentText(), slider_decimationGoal->value() / 100.0f);
m_plugin->decimate(
m_schnapps->getSelectedMap()->getName(),
combo_positionVBO->currentText(),
combo_normalVBO->currentText(),
slider_decimationGoal->value() / 100.0f,
checkbox_halfCollapse->checkState() == Qt::Checked
);
}
......
......@@ -67,8 +67,6 @@ public:
~Surface_Render_Plugin()
{}
private:
virtual bool enable();
virtual void disable();
......@@ -99,7 +97,6 @@ private slots:
void appsFinished();
public slots:
// slots for Python calls
void changePositionVBO(const QString& view, const QString& map, const QString& vbo);
......@@ -114,8 +111,6 @@ public slots:
void changeEdgeColor(const QString& view, const QString& map, float r, float g, float b);
void changeVertexColor(const QString& view, const QString& map, float r, float g, float b);
protected:
Surface_Render_DockTab* m_dockTab;
QHash<View*, QHash<MapHandlerGen*, MapParameters> > h_viewParameterSet;
......
......@@ -102,6 +102,31 @@ public:
void approximate(Dart d) ;
} ;
template <typename PFP, typename T>
class Approximator_InterpolateAlongEdge : public Approximator<PFP, T, EDGE>
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
protected:
const VertexAttribute<VEC3, MAP>& m_position ;
const EdgeAttribute<VEC3, MAP>& m_approximatedPosition ;
public:
Approximator_InterpolateAlongEdge(MAP& m, VertexAttribute<T, MAP>& attr, const VertexAttribute<VEC3, MAP>& position, const EdgeAttribute<VEC3, MAP>& approximatedPosition, Predictor<PFP, T>* pred = NULL) :
Approximator<PFP, T, EDGE>(m, attr, pred),
m_position(position),
m_approximatedPosition(approximatedPosition)
{}
~Approximator_InterpolateAlongEdge()
{}
ApproximatorType getType() const { return A_OTHER ; }
bool init() ;
void approximate(Dart d) ;
} ;
template <typename PFP, typename T>
class Approximator_HalfCollapse : public Approximator<PFP, T, DART>
{
......
......@@ -230,6 +230,34 @@ void Approximator_MidEdge<PFP,T>::approximate(Dart d)
}
}
/************************************************************************************
* INTERPOLATE ALONG EDGE *
************************************************************************************/
template <typename PFP, typename T>
bool Approximator_InterpolateAlongEdge<PFP,T>::init()
{
return this->m_approx.isValid() && m_position.isValid() && m_approximatedPosition.isValid() ;
}
template <typename PFP, typename T>
void Approximator_InterpolateAlongEdge<PFP,T>::approximate(Dart d)
{
Dart dd = this->m_map.phi1(d) ;
const VEC3& p1 = m_position[d] ;
const VEC3& p2 = m_position[dd] ;
const VEC3& p = m_approximatedPosition[d] ;
VEC3 p1p2 = p2 - p1;
VEC3 p1p = p1 - p;
REAL s = p1p * p1p2;
s /= p1p2.norm2();
s = std::max(std::min(s, REAL(1)) , REAL(0));
this->m_approx[d] = this->m_attr[dd] * s + this->m_attr[d] * (REAL(1) - s) ;
}
/************************************************************************************
* HALF COLLAPSE *
************************************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment