Skip to content

Commit

Permalink
Merge pull request #1087 from kerautret/SaveLightPosition
Browse files Browse the repository at this point in the history
Save light position
  • Loading branch information
dcoeurjo committed Dec 12, 2015
2 parents 102793a + 421b495 commit 1d444dd
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
(Roland Denis, [#1060](https://github.com/DGtal-team/DGtal/pull/1060))

- *IO*

- In the Viewer3D, the light source position is now saved in the
QGLViewer state file (.qglviewer.xml). (Bertrand Kerautret
[#1087](https://github.com/DGtal-team/DGtal/pull/1087))

- Minor improvements of default settings in Viewer3D. (David
Coeurjolly, [#1066](https://github.com/DGtal-team/DGtal/pull/1066))

Expand Down
27 changes: 26 additions & 1 deletion src/DGtal/io/viewers/Viewer3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,33 @@ namespace DGtal



/**
* @brief Overload of the QGLViewer method which returns an XML
* QDomElement representing the QGLViewer state. This overload adds the light
* position attribute.
*
* @param name the name of the QDomElement tag.
* @param document the QDomElement factory used to create QDomElement.
* @see initFromDOMElement
*/
virtual QDomElement domElement(const QString& name, QDomDocument& document) const;



/**
* @brief Overload of the QGLViewer method which restores the
* viewer state from a QDomDocument element. This overload
* recovers and loads default viewer attributes with the add of the
* the light position.
*
* @param element QDomDocument used to apply the restoration.
*
* @see domElement
*/
virtual void initFromDOMElement(const QDomElement& element);




// ------------------------- Internals ------------------------------------
private:

Expand Down
62 changes: 60 additions & 2 deletions src/DGtal/io/viewers/Viewer3D.ih
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@

#include <limits>
#include <QColor>

#include <QTextEdit>
#include <QMessageBox>
#include <QTextStream>
#include <QDir>

#include <cstdlib>
#include "DGtal/io/CDrawableWithDisplay3D.h"
Expand All @@ -70,7 +73,7 @@ DGtal::Viewer3D<Space, KSpace>::rotateDomain(Image2DDomainD3D &anDom, double ang
pt[1] = (int) (anDom.point1[1]+anDom.point2[1]+anDom.point3[1]+anDom.point4[1])/4.0;
pt[2] = (int) (anDom.point1[2]+anDom.point2[2]+anDom.point3[2]+anDom.point4[2])/4.0;
rotateImageVertex(anDom, angleRotation, rotationDir);

std::vector<typename DGtal::Display3D<Space, KSpace>::LineD3D> &aVectLine = Viewer3D<Space, KSpace>::myLineSetList.at(anDom.myLineSetIndex);
for(unsigned int i = 0; i< aVectLine.size();i++){
typename DGtal::Display3D<Space, KSpace>::LineD3D &aLine = aVectLine.at(i);
Expand Down Expand Up @@ -1707,3 +1710,58 @@ DGtal::Viewer3D<Space, KSpace>::glUpdateTextureImages(const VectorTextureImage
}
}



template< typename Space, typename KSpace>
QDomElement
DGtal::Viewer3D<Space, KSpace>::domElement(const QString& name, QDomDocument& document) const
{
// Creates a custom node for a light position
QDomElement de = document.createElement("Light");
de.setAttribute("pos_light_phi", myLightPhi);
de.setAttribute("pos_light_theta", myLightTheta);
de.setAttribute("pos_light_r", myLightR);
// Get default state domElement and append custom node
QDomElement res = QGLViewer::domElement(name, document);
res.appendChild(de);
return res;
}





template< typename Space, typename KSpace>
void
DGtal::Viewer3D<Space, KSpace>::initFromDOMElement(const QDomElement& element)
{
// Restore standard state
QGLViewer::initFromDOMElement(element);
QDomElement child=element.firstChild().toElement();
while (!child.isNull())
{
if (child.tagName() == "Light")
{
if (child.hasAttribute("pos_light_phi")){
myLightPhi = child.attribute("pos_light_phi").toDouble();
}

if (child.hasAttribute("pos_light_theta")){
myLightTheta = child.attribute("pos_light_theta").toDouble();
}
if (child.hasAttribute("pos_light_r")){
myLightR = child.attribute("pos_light_r").toDouble();
}
}
child = child.nextSibling().toElement();
}

myLightPosition[0] = myLightR*cos(myLightTheta)*cos(myLightPhi);
myLightPosition[1] = myLightR*cos(myLightTheta)*sin(myLightPhi);
myLightPosition[2] = myLightR*sin(myLightTheta);
myLightPosition[3] = 0.0;
updateGL();
}



0 comments on commit 1d444dd

Please sign in to comment.