Commit 0df500ca authored by Pierre Kraemer's avatar Pierre Kraemer

Merge branch 'develop' into 'develop'

corrections on BivariatePolynomials

See merge request !76
parents 6b21de4d d37e9e32
...@@ -146,12 +146,12 @@ public: // methods ...@@ -146,12 +146,12 @@ public: // methods
*/ */
Frame(const VEC3& compressedFrame) ; Frame(const VEC3& compressedFrame) ;
~Frame() {} ; ~Frame() {}
/** /**
* Returns a compressed version of the current local frame * Returns a compressed version of the current local frame
*/ */
const VEC3& getCompressed() const { return m_EulerAngles ; } ; const VEC3& getCompressed() const { return m_EulerAngles ; }
/** /**
* Returns a decompressed frame (set of 3 VEC3) * Returns a decompressed frame (set of 3 VEC3)
...@@ -190,7 +190,7 @@ public: // methods ...@@ -190,7 +190,7 @@ public: // methods
lf.getFrame(X,Y,Z) ; lf.getFrame(X,Y,Z) ;
out << std::endl << "Decompressed : " << std::endl << X << std::endl << Y << std::endl << Z ; out << std::endl << "Decompressed : " << std::endl << X << std::endl << Y << std::endl << Z ;
return out ; return out ;
} ; }
private : // private constants private : // private constants
// The reference frame (X,Y,Z) can be any orthonormal // The reference frame (X,Y,Z) can be any orthonormal
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
#include <Geometry/vector_gen.h>
//#include <Eigen/Core> //#include <Eigen/Core>
//#include <Eigen/Dense> //#include <Eigen/Dense>
//#include <Eigen/Cholesky> //#include <Eigen/Cholesky>
...@@ -26,9 +28,9 @@ template <typename Tscalar, typename Tcoef> ...@@ -26,9 +28,9 @@ template <typename Tscalar, typename Tcoef>
class BivariatePolynomials class BivariatePolynomials
{ {
private : private :
const int degree ; // (bi-)degree of the polynomial (=4) int degree ; // (bi-)degree of the polynomial (=4)
const int nb_coefs ; // number of coefs (=15) int nb_coefs ; // number of coefs (=15)
Tcoef* coefs; // table of coefficients Tcoef* coefs; // table of coefficients
public : public :
// construction, destruction and initialization // construction, destruction and initialization
...@@ -36,19 +38,19 @@ public : ...@@ -36,19 +38,19 @@ public :
BivariatePolynomials(BivariatePolynomials const &); BivariatePolynomials(BivariatePolynomials const &);
~BivariatePolynomials(); ~BivariatePolynomials();
int get_degree () { return degree; } int get_degree () const { return degree; }
int get_nb_coefs () { return nb_coefs; } int get_nb_coefs () const { return nb_coefs; }
// evaluation // evaluation
Tcoef evaluate_at (Tscalar u, Tscalar v) const; Tcoef evaluate_at (Tscalar u, Tscalar v) const;
Tcoef evaluate_at (const Geom::Vec3<Tscalar>& tu, const Geom::Vec3<Tscalar>& tv, const Geom::Vec3<Tscalar>& n, const Geom::Vec3<Tscalar>& eval_dir) const; Tcoef evaluate_at (const Geom::Vector<3,Tscalar>& tu, const Geom::Vector<3,Tscalar>& tv, const Geom::Vector<3,Tscalar>& n, const Geom::Vector<3,Tscalar>& eval_dir) const;
// I/O // I/O
const Tcoef& get_coef (int du, int dv) const {assert ((du>=0 && dv <=degree && dv>=0 && dv <=degree) || !" bi-degree is incorrect"); return get_coef(index(l,m));} const Tcoef& get_coef (int du, int dv) const {assert ((du>=0 && dv <=degree && dv>=0 && dv <=degree) || !" bi-degree is incorrect"); return get_coef(index(du,dv));}
Tcoef& get_coef (int du, int dv) {assert ((du>=0 && dv <=degree && dv>=0 && dv <=degree) || !" bi-degree is incorrect"); return get_coef(index(l,m));} Tcoef& get_coef (int du, int dv) {assert ((du>=0 && dv <=degree && dv>=0 && dv <=degree) || !" bi-degree is incorrect"); return get_coef(index(du,dv));}
Tcoef* get_coef_tab () {return coefs;} Tcoef* get_coef_tab () const {return coefs;}
template <typename TS,typename TC> friend std::ostream & operator<< (std::ostream & os, const BivariatePolynomials<TS,TC> & sh); template <typename TS,typename TC> friend std::ostream & operator<< (std::ostream & os, const BivariatePolynomials<TS,TC> & sh);
......
...@@ -75,7 +75,7 @@ Tcoef BivariatePolynomials<Tscalar,Tcoef>::evaluate_at (Tscalar u, Tscalar v) co ...@@ -75,7 +75,7 @@ Tcoef BivariatePolynomials<Tscalar,Tcoef>::evaluate_at (Tscalar u, Tscalar v) co
} }
template <typename Tscalar,typename Tcoef> template <typename Tscalar,typename Tcoef>
Tcoef BivariatePolynomials<Tscalar,Tcoef>::evaluate_at (const Geom::Vec3<Tscalar>& tu, const Geom::Vec3<Tscalar>& tv, const Geom::Vec3<Tscalar>& n, const Geom::Vec3<Tscalar>& eval_dir) const; Tcoef BivariatePolynomials<Tscalar,Tcoef>::evaluate_at (const Geom::Vector<3,Tscalar>& tu, const Geom::Vector<3,Tscalar>& tv, const Geom::Vector<3,Tscalar>& n, const Geom::Vector<3,Tscalar>& eval_dir) const
{ {
Tscalar u = tu*eval_dir; Tscalar u = tu*eval_dir;
Tscalar v = tv*eval_dir; Tscalar v = tv*eval_dir;
...@@ -95,7 +95,7 @@ I/O ...@@ -95,7 +95,7 @@ I/O
template <typename Tscalar,typename Tcoef> template <typename Tscalar,typename Tcoef>
std::ostream & operator << (std::ostream & os, const BivariatePolynomials<Tscalar,Tcoef> & p) std::ostream & operator << (std::ostream & os, const BivariatePolynomials<Tscalar,Tcoef> & p)
{ {
for (int d = 0; d <= sh.degree; d++) for (int d = 0; d <= p.degree; d++)
{ {
for (int du = d; du >=0 ; du--) for (int du = d; du >=0 ; du--)
os << p.get_coef(du,d-du) << "\t"; os << p.get_coef(du,d-du) << "\t";
......
...@@ -14,15 +14,15 @@ ...@@ -14,15 +14,15 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="4" column="0" colspan="3"> <item row="0" column="0">
<widget class="QCheckBox" name="checkbox_halfCollapse"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Half Collapse</string> <string>Position :</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1" colspan="2"> <item row="0" column="1">
<widget class="QComboBox" name="combo_normalVBO"> <widget class="QComboBox" name="combo_positionVBO">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -36,13 +36,6 @@ ...@@ -36,13 +36,6 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="5" column="0" colspan="3">
<widget class="QPushButton" name="button_decimate">
<property name="text">
<string>Decimate</string>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
...@@ -50,22 +43,30 @@ ...@@ -50,22 +43,30 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="3"> <item row="1" column="1">
<widget class="QCheckBox" name="checkbox_fragInterp"> <widget class="QComboBox" name="combo_normalVBO">
<property name="text"> <property name="sizePolicy">
<string>Fragment interpolation</string> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<item>
<property name="text">
<string>- select VBO -</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
<string>Position :</string> <string>Tangent :</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" colspan="2"> <item row="2" column="1">
<widget class="QComboBox" name="combo_positionVBO"> <widget class="QComboBox" name="combo_tangentVBO">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -79,20 +80,36 @@ ...@@ -79,20 +80,36 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="6" column="2"> <item row="3" column="0">
<spacer name="verticalSpacer"> <widget class="QLabel" name="label_5">
<property name="orientation"> <property name="text">
<enum>Qt::Vertical</enum> <string>BiNormal :</string>
</property> </property>
<property name="sizeHint" stdset="0"> </widget>
<size> </item>
<width>20</width> <item row="3" column="1">
<height>40</height> <widget class="QComboBox" name="combo_binormalVBO">
</size> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
</spacer> <item>
<property name="text">
<string>- select VBO -</string>
</property>
</item>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="checkbox_fragInterp">
<property name="text">
<string>Fragment interpolation</string>
</property>
</widget>
</item> </item>
<item row="3" column="0" colspan="3"> <item row="5" column="0" colspan="2">
<widget class="QSlider" name="slider_decimationGoal"> <widget class="QSlider" name="slider_decimationGoal">
<property name="maximum"> <property name="maximum">
<number>100</number> <number>100</number>
...@@ -105,6 +122,33 @@ ...@@ -105,6 +122,33 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="checkbox_halfCollapse">
<property name="text">
<string>Half Collapse</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QPushButton" name="button_decimate">
<property name="text">
<string>Decimate</string>
</property>
</widget>
</item>
<item row="8" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#include "dialog_computeRadianceDistance.h" #include "dialog_computeRadianceDistance.h"
#include "Utils/sphericalHarmonics.h" #include "Utils/sphericalHarmonics.h"
#include "Utils/bivariatePolynomials.h"
#include "Utils/Shaders/shaderRadiancePerVertex.h" #include "Utils/Shaders/shaderRadiancePerVertex.h"
#include "Utils/Shaders/shaderRadiancePerVertex_P.h"
#include "Utils/drawer.h" #include "Utils/drawer.h"
#include "Algo/Decimation/decimation.h" #include "Algo/Decimation/decimation.h"
...@@ -21,7 +23,11 @@ struct MapParameters ...@@ -21,7 +23,11 @@ struct MapParameters
{ {
MapParameters() : MapParameters() :
positionVBO(NULL), positionVBO(NULL),
tangentVBO(NULL),
normalVBO(NULL), normalVBO(NULL),
binormalVBO(NULL),
radiancePerVertexShader(NULL),
radiancePerVertexPShader(NULL),
radianceTexture(NULL), radianceTexture(NULL),
paramVBO(NULL), paramVBO(NULL),
positionApproximator(NULL), positionApproximator(NULL),
...@@ -33,11 +39,16 @@ struct MapParameters ...@@ -33,11 +39,16 @@ struct MapParameters
unsigned int nbVertices; unsigned int nbVertices;
Utils::VBO* positionVBO; Utils::VBO* positionVBO;
Utils::VBO* tangentVBO;
Utils::VBO* normalVBO; Utils::VBO* normalVBO;
Utils::VBO* binormalVBO;
CGoGN::Utils::ShaderRadiancePerVertex* radiancePerVertexShader; CGoGN::Utils::ShaderRadiancePerVertex* radiancePerVertexShader;
CGoGN::Utils::ShaderRadiancePerVertex_P* radiancePerVertexPShader;
VertexAttribute<Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>, PFP2::MAP> radiance; VertexAttribute<Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>, PFP2::MAP> radiance;
VertexAttribute<Utils::BivariatePolynomials<PFP2::REAL, PFP2::VEC3>, PFP2::MAP> radiance_P;
Utils::Texture<2, Geom::Vec3f>* radianceTexture; Utils::Texture<2, Geom::Vec3f>* radianceTexture;
VertexAttribute<Geom::Vec2i, PFP2::MAP> param; VertexAttribute<Geom::Vec2i, PFP2::MAP> param;
Utils::VBO* paramVBO; Utils::VBO* paramVBO;
...@@ -97,7 +108,8 @@ private slots: ...@@ -97,7 +108,8 @@ private slots:
void vboRemoved(Utils::VBO* vbo); void vboRemoved(Utils::VBO* vbo);
void attributeModified(unsigned int orbit, QString nameAttr); void attributeModified(unsigned int orbit, QString nameAttr);
void importFromFileDialog(); void importFromFileDialog_SH();
void importFromFileDialog_P();
void openComputeRadianceDistanceDialog(); void openComputeRadianceDistanceDialog();
void computeRadianceDistanceFromDialog(); void computeRadianceDistanceFromDialog();
...@@ -106,7 +118,8 @@ public slots: ...@@ -106,7 +118,8 @@ public slots:
// slots for Python calls // slots for Python calls
void changePositionVBO(const QString& map, const QString& vbo); void changePositionVBO(const QString& map, const QString& vbo);
void changeNormalVBO(const QString& map, const QString& vbo); void changeNormalVBO(const QString& map, const QString& vbo);
MapHandlerGen* importFromFile(const QString& fileName); MapHandlerGen* importFromFile_SH(const QString& fileName);
MapHandlerGen* importFromFile_P(const QString& fileName);
void decimate( void decimate(
const QString& mapName, const QString& mapName,
const QString& positionAttributeName, const QString& positionAttributeName,
...@@ -148,7 +161,8 @@ protected: ...@@ -148,7 +161,8 @@ protected:
std::vector<unsigned int> exportNbVert; std::vector<unsigned int> exportNbVert;
unsigned int nextExportIndex; unsigned int nextExportIndex;
QAction* m_importAction; QAction* m_importSHAction;
QAction* m_importPAction;
static bool isInHemisphere(double x, double y, double z, void* u) static bool isInHemisphere(double x, double y, double z, void* u)
{ // true iff [x,y,z] and u have the same direction { // true iff [x,y,z] and u have the same direction
......
...@@ -32,6 +32,8 @@ private: ...@@ -32,6 +32,8 @@ private:
private slots: private slots:
void positionVBOChanged(int index); void positionVBOChanged(int index);
void normalVBOChanged(int index); void normalVBOChanged(int index);
void tangentVBOChanged(int index);
void binormalVBOChanged(int index);
void fragmentInterpolationChanged(int state); void fragmentInterpolationChanged(int state);
void decimateClicked(); void decimateClicked();
...@@ -40,6 +42,10 @@ private: ...@@ -40,6 +42,10 @@ private:
void removePositionVBO(QString name); void removePositionVBO(QString name);
void addNormalVBO(QString name); void addNormalVBO(QString name);
void removeNormalVBO(QString name); void removeNormalVBO(QString name);
void addTangentVBO(QString name);
void removeTangentVBO(QString name);
void addBiNormalVBO(QString name);
void removeBiNormalVBO(QString name);
void updateMapParameters(); void updateMapParameters();
}; };
......
#include "surface_radiance.h" #include "surface_radiance.h"
#include "meshTableSurfaceRadiance.h" #include "meshTableSurfaceRadiance.h"
#include "meshTableSurfaceRadiance_P.h"
#include "halfEdgeSelectorRadiance.h" #include "halfEdgeSelectorRadiance.h"
#include "edgeSelectorRadiance.h" #include "edgeSelectorRadiance.h"
...@@ -29,9 +31,13 @@ bool Surface_Radiance_Plugin::enable() ...@@ -29,9 +31,13 @@ bool Surface_Radiance_Plugin::enable()
m_dockTab = new Surface_Radiance_DockTab(m_schnapps, this); m_dockTab = new Surface_Radiance_DockTab(m_schnapps, this);
m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Radiance"); m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Radiance");
m_importAction = new QAction("import", this); m_importSHAction = new QAction("importSH", this);
m_schnapps->addMenuAction(this, "Radiance;Import", m_importAction); m_schnapps->addMenuAction(this, "Radiance;Import (SH)", m_importSHAction);
connect(m_importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog())); connect(m_importSHAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog_SH()));
m_importPAction = new QAction("importP", this);
m_schnapps->addMenuAction(this, "Radiance;Import (P)", m_importPAction);
connect(m_importPAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog_P()));
m_computeRadianceDistanceDialog = new Dialog_ComputeRadianceDistance(m_schnapps); m_computeRadianceDistanceDialog = new Dialog_ComputeRadianceDistance(m_schnapps);
...@@ -72,7 +78,7 @@ void Surface_Radiance_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -72,7 +78,7 @@ void Surface_Radiance_Plugin::drawMap(View* view, MapHandlerGen* map)
{ {
const MapParameters& p = h_mapParameterSet[map]; const MapParameters& p = h_mapParameterSet[map];
if(p.positionVBO && p.normalVBO) if(p.radiancePerVertexShader && p.positionVBO && p.normalVBO)
{ {
p.radiancePerVertexShader->setAttributePosition(p.positionVBO); p.radiancePerVertexShader->setAttributePosition(p.positionVBO);
p.radiancePerVertexShader->setAttributeNormal(p.normalVBO); p.radiancePerVertexShader->setAttributeNormal(p.normalVBO);
...@@ -88,6 +94,25 @@ void Surface_Radiance_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -88,6 +94,25 @@ void Surface_Radiance_Plugin::drawMap(View* view, MapHandlerGen* map)
map->draw(p.radiancePerVertexShader, Algo::Render::GL2::TRIANGLES); map->draw(p.radiancePerVertexShader, Algo::Render::GL2::TRIANGLES);
glDisable(GL_POLYGON_OFFSET_FILL); glDisable(GL_POLYGON_OFFSET_FILL);
} }
if(p.radiancePerVertexPShader && p.positionVBO && p.normalVBO && p.tangentVBO && p.binormalVBO)
{
p.radiancePerVertexPShader->setAttributePosition(p.positionVBO);
p.radiancePerVertexPShader->setAttributeTangent(p.tangentVBO);
p.radiancePerVertexPShader->setAttributeNormal(p.normalVBO);
p.radiancePerVertexPShader->setAttributeBiNormal(p.binormalVBO);
p.radiancePerVertexPShader->setAttributeRadiance(p.paramVBO, p.radianceTexture, GL_TEXTURE1);
qglviewer::Vec c = view->getCurrentCamera()->position();
PFP2::VEC3 camera(c.x, c.y, c.z);
p.radiancePerVertexPShader->setCamera(Geom::Vec3f(camera[0], camera[1], camera[2])); // convert to Vec3f because PFP2 can hold Vec3d !
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
map->draw(p.radiancePerVertexPShader, Algo::Render::GL2::TRIANGLES);
glDisable(GL_POLYGON_OFFSET_FILL);
}
} }
...@@ -141,6 +166,8 @@ void Surface_Radiance_Plugin::vboAdded(Utils::VBO *vbo) ...@@ -141,6 +166,8 @@ void Surface_Radiance_Plugin::vboAdded(Utils::VBO *vbo)
{ {
m_dockTab->addPositionVBO(QString::fromStdString(vbo->name())); m_dockTab->addPositionVBO(QString::fromStdString(vbo->name()));
m_dockTab->addNormalVBO(QString::fromStdString(vbo->name())); m_dockTab->addNormalVBO(QString::fromStdString(vbo->name()));
m_dockTab->addTangentVBO(QString::fromStdString(vbo->name()));
m_dockTab->addBiNormalVBO(QString::fromStdString(vbo->name()));
} }
} }
} }
...@@ -155,6 +182,8 @@ void Surface_Radiance_Plugin::vboRemoved(Utils::VBO *vbo) ...@@ -155,6 +182,8 @@ void Surface_Radiance_Plugin::vboRemoved(Utils::VBO *vbo)
{ {
m_dockTab->removePositionVBO(QString::fromStdString(vbo->name())); m_dockTab->removePositionVBO(QString::fromStdString(vbo->name()));
m_dockTab->removeNormalVBO(QString::fromStdString(vbo->name())); m_dockTab->removeNormalVBO(QString::fromStdString(vbo->name()));
m_dockTab->removeTangentVBO(QString::fromStdString(vbo->name()));
m_dockTab->removeBiNormalVBO(QString::fromStdString(vbo->name()));
} }
} }
...@@ -167,6 +196,14 @@ void Surface_Radiance_Plugin::vboRemoved(Utils::VBO *vbo) ...@@ -167,6 +196,14 @@ void Surface_Radiance_Plugin::vboRemoved(Utils::VBO *vbo)
{ {
mapParam.normalVBO = NULL; mapParam.normalVBO = NULL;
} }
if(mapParam.tangentVBO == vbo)
{
mapParam.tangentVBO = NULL;
}
if(mapParam.binormalVBO == vbo)
{
mapParam.binormalVBO = NULL;
}
} }
void Surface_Radiance_Plugin::attributeModified(unsigned int orbit, QString nameAttr) void Surface_Radiance_Plugin::attributeModified(unsigned int orbit, QString nameAttr)
...@@ -177,12 +214,22 @@ void Surface_Radiance_Plugin::attributeModified(unsigned int orbit, QString name ...@@ -177,12 +214,22 @@ void Surface_Radiance_Plugin::attributeModified(unsigned int orbit, QString name
} }
} }
void Surface_Radiance_Plugin::importFromFileDialog() void Surface_Radiance_Plugin::importFromFileDialog_SH()
{
QStringList fileNames = QFileDialog::getOpenFileNames(m_schnapps, "Import surface with radiance (SH)", m_schnapps->getAppPath(), "Surface with radiance Files (*.ply)");
QStringList::Iterator it = fileNames.begin();
while(it != fileNames.end()) {
importFromFile_SH(*it);
++it;
}
}
void Surface_Radiance_Plugin::importFromFileDialog_P()
{ {
QStringList fileNames = QFileDialog::getOpenFileNames(m_schnapps, "Import surface with radiance", m_schnapps->getAppPath(), "Surface with radiance Files (*.ply)"); QStringList fileNames = QFileDialog::getOpenFileNames(m_schnapps, "Import surface with radiance (P)", m_schnapps->getAppPath(), "Surface with radiance Files (*.ply)");
QStringList::Iterator it = fileNames.begin(); QStringList::Iterator it = fileNames.begin();
while(it != fileNames.end()) { while(it != fileNames.end()) {
importFromFile(*it); importFromFile_P(*it);
++it; ++it;
} }
} }
...@@ -264,7 +311,7 @@ void Surface_Radiance_Plugin::changeNormalVBO(const QString& map, const QString& ...@@ -264,7 +311,7 @@ void Surface_Radiance_Plugin::changeNormalVBO(const QString& map, const QString&
} }
} }
MapHandlerGen* Surface_Radiance_Plugin::importFromFile(const QString& fileName) MapHandlerGen* Surface_Radiance_Plugin::importFromFile_SH(const QString& fileName)
{ {
QFileInfo fi(fileName); QFileInfo fi(fileName);
if(fi.exists()) if(fi.exists())
...@@ -348,6 +395,90 @@ MapHandlerGen* Surface_Radiance_Plugin::importFromFile(const QString& fileName) ...@@ -348,6 +395,90 @@ MapHandlerGen* Surface_Radiance_Plugin::importFromFile(const QString& fileName)
return NULL; return NULL;
} }
MapHandlerGen* Surface_Radiance_Plugin::importFromFile_P(const QString& fileName)
{
QFileInfo fi(fileName);
if(fi.exists())
{
MapHandlerGen* mhg = m_schnapps->addMap(fi.baseName(), 2);
if(mhg)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
PFP2::MAP* map = mh->getMap();
MeshTablesSurface_Radiance_P importer(*map);
if (!importer.importPLY<Utils::BivariatePolynomials<PFP2::REAL, PFP2::VEC3> >(fileName.toStdString()))
{
std::cout << "could not import " << fileName.toStdString() << std::endl;
return NULL;
}
CGoGN::Algo::Surface::Import::importMesh<PFP2>(*map, importer);
// get vertex position attribute
VertexAttribute<PFP2::VEC3, PFP2::MAP> position = map->getAttribute<PFP2::VEC3, VERTEX, PFP2::MAP>("position") ;
VertexAttribute<PFP2::VEC3, PFP2::MAP> tangent = map->getAttribute<PFP2::VEC3, VERTEX, PFP2::MAP>("tangent");
VertexAttribute<PFP2::VEC3, PFP2::MAP> normal = map->getAttribute<PFP2::VEC3, VERTEX, PFP2::MAP>("normal");
VertexAttribute<PFP2::VEC3, PFP2::MAP> binormal = map->getAttribute<PFP2::VEC3, VERTEX, PFP2::MAP>("binormal");
mh->registerAttribute(position);
mh->registerAttribute(tangent);
mh->registerAttribute(normal);
mh->registerAttribute(binormal);
MapParameters& mapParams = h_mapParameterSet[mhg];
mapParams.nbVertices = Algo::Topo::getNbOrbits<VERTEX>(*map);
mapParams.radiance_P = map->getAttribute<Utils::BivariatePolynomials<PFP2::REAL, PFP2::VEC3>, VERTEX, PFP2::MAP>("radiance") ;
mapParams.radianceTexture = new Utils::Texture<2, Geom::Vec3f>(GL_FLOAT);
mapParams.param = map->checkAttribute<Geom::Vec2i, VERTEX, PFP2::MAP>("param");
unsigned int nbCoefs = mapParams.radiance_P[map->begin()].get_nb_coefs();
// create texture
unsigned int nbv_nbc = Algo::Topo::getNbOrbits<VERTEX>(*map) * nbCoefs;
unsigned int size = 1;
while (size * size < nbv_nbc)
size <<= 1;
mapParams.radianceTexture->create(Geom::Vec2i(size, size));
// fill texture
unsigned int count = 0;
foreach_cell<VERTEX>(*map, [&] (Vertex v)
{
PFP2::VEC3* coefs = mapParams.radiance_P[v].get_coef_tab();
unsigned int i = count / size;
unsigned int j = count % size;
mapParams.param[v] = Geom::Vec2i(i, j) ; // first index for current vertex
for (unsigned int l = 0 ; l <= nbCoefs ; ++l)
{
i = count / size;
j = count % size;
(*(mapParams.radianceTexture))(i,j) = coefs[l];
++count;
}
}) ;
// resulting texture : PB0_v0, PB1_v0, ..., PB14_v0, PB0_v1, ...
// resulting param : param[vx] points to PB0_vx
// the size of the texture is needed to know where to do the divisions and modulos.
mapParams.radianceTexture->update();
mapParams.paramVBO = new Utils::VBO();
mapParams.paramVBO->updateData(mapParams.param);