31#if defined(Viewer3D_RECURSES)
32#error Recursive header files inclusion detected in Viewer3D.h
35#define Viewer3D_RECURSES
37#if !defined Viewer3D_h
43#include "DGtal/base/Common.h"
54#define GL_SILENCE_DEPRECATION
56#include <OpenGL/glu.h>
62#include <QApplication>
64#include <QGLViewer/qglviewer.h>
68#include "DGtal/kernel/SpaceND.h"
69#include "DGtal/topology/KhalimskySpaceND.h"
70#include "DGtal/base/CountedPtr.h"
71#include "DGtal/io/Display3D.h"
72#include "DGtal/math/BasicMathFunctions.h"
74#include "DGtal/kernel/CSpace.h"
129 template <
typename TSpace = SpaceND<3>,
130 typename TKSpace = KhalimskySpaceND<3>>
179 boost::ignore_unused_variable_warning( viewer );
180 boost::ignore_unused_variable_warning( event );
191 boost::ignore_unused_variable_warning( viewer );
201 boost::ignore_unused_variable_warning( viewer );
210 boost::ignore_unused_variable_warning( viewer );
221 boost::ignore_unused_variable_warning( viewer );
236 boost::ignore_unused_variable_warning( viewer );
237 boost::ignore_unused_variable_warning( point );
251 boost::ignore_unused_variable_warning( viewer );
252 boost::ignore_unused_variable_warning( event );
266 boost::ignore_unused_variable_warning( viewer );
267 boost::ignore_unused_variable_warning( event );
282 boost::ignore_unused_variable_warning( viewer );
283 boost::ignore_unused_variable_warning( event );
386 glEnable(GL_NORMALIZE);
523 template<
typename TDomain>
525 double xBottomLeft=0.0,
double yBottomLeft=0.0,
double zBottomLeft=0.0, std::string mode=
"BoundingBox")
530 myDomainWidth = (aDomain.upperBound())[0]-(aDomain.lowerBound())[0]+1;
531 myDomainHeight = (aDomain.upperBound())[1]-(aDomain.lowerBound())[1]+1;
546 double xBottomLeft,
double yBottomLeft,
double zBottomLeft);
556 double yTranslation=0.0,
double zTranslation=0.0);
606 if(img.myImageHeight>0 && img.myImageWidth>0)
608 myTabImage =
new unsigned int [img.myImageWidth*img.myImageHeight];
609 for(
unsigned int i=0; i<img.myImageWidth*img.myImageHeight; i++)
640 template <
typename TImageType,
typename TFunctor>
644 double xBottomLeft=0.0,
double yBottomLeft=0.0,
double zBottomLeft=0.0,
651 myImageWidth = (image.domain().upperBound())[0]-(image.domain().lowerBound())[0]+1;
652 myImageHeight = (image.domain().upperBound())[1]-(image.domain().lowerBound())[1]+1;
669 double xBottomLeft,
double yBottomLeft,
double zBottomLeft);
705 template <
typename TImageType,
typename TFunctor>
707 double yTranslation=0.0,
double zTranslation=0.0)
711 assert ( (image.domain().upperBound())[0]-(image.domain().lowerBound())[0]+1==
static_cast<int>(
myImageWidth) &&
712 (image.domain().upperBound())[1]-(image.domain().lowerBound())[1]+1==
static_cast<int>(
myImageHeight));
720 for(
typename TImageType::Domain::ConstIterator it = image.domain().begin(), itend=image.domain().end();
780 template <
typename TDrawableWithViewer3D>
852 template <
typename TImageType,
typename TFunctor>
854 void updateTextureImage(
unsigned int imageIndex,
const TImageType & image,
const TFunctor & aFunctor,
855 double xTranslation=0.0,
double yTranslation=0.0,
double zTranslation=0.0,
871 double xPosition,
double yPosition,
896 template<
typename TDomain>
910 double xPosition,
double yPosition,
921 double yTranslation,
double zTranslation);
929 std::vector<typename DGtal::Viewer3D< Space , KSpace >::LineD3D>
937 std::vector<typename DGtal::Viewer3D< Space , KSpace >::LineD3D>
949 template <
typename TContainer >
979 QGLViewer::drawLight( light );
984 QGLViewer::drawLight( light, zoom );
1061 return dist1 > dist2;
1112 double c1x=0.0, c1y=0.0, c1z=0.0;
1113 double c2x=0.0, c2y=0.0, c2z=0.0;
1114 for(
unsigned int i=0; i< q1.
vertices.size(); i++){
1119 for(
unsigned int i=0; i< q2.
vertices.size(); i++){
1125 qglviewer::Vec center1 ( c1x/(
double)q1.
vertices.size(),c1y/(
double)q1.
vertices.size(), c1z/(
double)q1.
vertices.size() );
1126 qglviewer::Vec center2 ( c2x/(
double)q2.
vertices.size(),c2y/(
double)q2.
vertices.size(), c2z/(
double)q2.
vertices.size() );
1173 virtual QDomElement
domElement(
const QString& name, QDomDocument& document)
const;
1368 typedef typename std::vector<typename Viewer3D<Space, KSpace>::CubeD3D>
VectorCubes;
1369 typedef typename std::vector<typename Viewer3D<Space, KSpace>::QuadD3D>
VectorQuad;
1370 typedef typename std::vector<typename Viewer3D<Space, KSpace>::LineD3D>
VectorLine;
1371 typedef typename std::vector<typename Viewer3D<Space, KSpace>::BallD3D>
VectorBall;
1372 typedef typename std::vector<typename Viewer3D<Space, KSpace>::TriangleD3D>
VectorTriangle;
1373 typedef typename std::vector<typename Viewer3D<Space, KSpace>::PolygonD3D>
VectorPolygon;
1377 typedef typename VectorCubes::iterator
ItCube;
1537 template<
typename TImageORDomain>
1541 double xB = (anImageOrDom.point1[0]+anImageOrDom.point2[0]+anImageOrDom.point3[0]+anImageOrDom.point4[0])/4.0;
1542 double yB = (anImageOrDom.point1[1]+anImageOrDom.point2[1]+anImageOrDom.point3[1]+anImageOrDom.point4[1])/4.0;
1543 double zB = (anImageOrDom.point1[2]+anImageOrDom.point2[2]+anImageOrDom.point3[2]+anImageOrDom.point4[2])/4.0;
1544 rotatePoint( anImageOrDom.point1[0], anImageOrDom.point1[1], anImageOrDom.point1[2], xB, yB, zB, angle, rotationDir);
1545 rotatePoint( anImageOrDom.point2[0], anImageOrDom.point2[1], anImageOrDom.point2[2], xB, yB, zB, angle, rotationDir);
1546 rotatePoint( anImageOrDom.point3[0], anImageOrDom.point3[1], anImageOrDom.point3[2], xB, yB, zB, angle, rotationDir);
1547 rotatePoint( anImageOrDom.point4[0], anImageOrDom.point4[1], anImageOrDom.point4[2], xB, yB, zB, angle, rotationDir);
1564 template <
typename TValues>
1567 double cx,
double cy,
double cz,
1670 template <
typename TSpace,
typename TKSpace>
1684#include "DGtal/io/viewers/Viewer3D.ih"
1691#undef Viewer3D_RECURSES
Structure representing an RGB triple with alpha component.
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
Aim: This semi abstract class defines the stream mechanism to display 3d primitive (like BallVector,...
int(* SelectCallbackFct)(void *viewer, DGtal::int32_t name, void *data)
Select callback function type.
std::map< DGtal::int32_t, std::vector< CubeD3D > > CubesMap
The type that maps identifier name -> vector of CubeD3D.
SelectCallbackFct getSelectCallback3D(DGtal::int32_t aName, void *&data) const
std::map< DGtal::int32_t, std::vector< QuadD3D > > QuadsMap
The type that maps identifier name -> vector of QuadD3D.
Space::RealPoint RealPoint
RealPoint type.
Aim: Implements basic operations that will be used in Point and Vector classes.
Viewer3D< Space, KSpace > & operator<<(const DGtal::Color &aColor)
qglviewer::Vec myDirSelector
void glCreateListPolygonsWired(const std::vector< VectorPolygon > &aVectPolygon, unsigned int idList)
bool myIsBackgroundDefault
true if the background is default
unsigned int myNbLineSetList
bool myViewWire
objects have shadows which follow the camera if false
void drawSomeLight(GLenum light) const
To call the protected method drawLight.
GLuint myTriangleSetListId
lists of the list to draw
virtual QString helpString() const
void setCameraPosition(double ax, double ay, double az)
const GLfloat myLambertRenderSpec
virtual void mouseMoveEvent(QMouseEvent *e)
const GLfloat myPlasticRenderSpec
virtual void mousePressEvent(QMouseEvent *e)
virtual void paintGL()
Overload of the QGLViewer method in order to change the order of display (to fix the QGLViewer axis d...
double camera_upVector[3]
camera up-vector
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
void sortQuadFromCamera()
void glCreateListQuadMapsWired(const typename Display3D< Space, KSpace >::QuadsMap &aQuadMap, unsigned int idList)
GLfloat myLightSpecularCoeffs[4]
GLfloat myLightDiffuseCoeffs[4]
bool myIsDoubleFaceRendering
true if is double face rendering
void setExtension(Extension *ext)
static void rotatePoint(TValues &x, TValues &y, TValues &z, double cx, double cy, double cz, double rotationAngle, ImageDirection rotationDir)
DGtal::Color myDefaultColor
the default color of the viewer
bool myLightPositionFixToCamera
void setCameraDirection(double ax, double ay, double az)
void setGLLightDiffuseCoefficients(const GLfloat lightDiffuseCoeffs[4])
qglviewer::Vec myOrig
information linked to the navigation in the viewer
bool myAutoSaveState
flag to save automatically or not the Viewer3d state when closing the viewer
GLfloat myLightPositionRefCameraDefault[3]
int myRefMouseXPos
the angle rotation increment used for interactive light move
void setNearFar(double _near, double _far)
virtual void closeEvent(QCloseEvent *e)
Overload the QWidget method to customize the viewer state auto saving. Now it save the viewer state i...
void sortPolygonFromCamera()
double myLigthRotationStep
GLfloat myLightAmbientCoeffs[4]
std::vector< GLTextureImage > myVectTextureImage
list of the images textures in this viewer
float myMeshDefaultLineWidth
unsigned char mySelectionColorShift
VectorCubes::iterator ItCube
void translateAn2DDomain(unsigned int domainIndex, double xTranslation, double yTranslation, double zTranslation)
GLuint myPolygonSetListWiredId
static void rotateImageVertex(TImageORDomain &anImageOrDom, double angle, ImageDirection rotationDir)
std::vector< typename Viewer3D< Space, KSpace >::TriangleD3D > VectorTriangle
virtual unsigned int getCurrentGLImageNumber()
void updateAn2DDomainOrientation(unsigned int imageIndex, double xPosition, double yPosition, double zPosition, ImageDirection newDirection)
TextureMode
the modes of representation of an image
void drawSomeLight(GLenum light, float zoom) const
To call the protected method drawLight.
void glCreateListPolygons(const std::vector< VectorPolygon > &aVectPolygon, unsigned int idList)
void selfDisplay(std::ostream &out) const
qglviewer::Vec mySelectedPoint
std::vector< typename Viewer3D< Space, KSpace >::BallD3D > VectorBall
Viewer3D(const KSpace &KSEmb)
virtual void keyPressEvent(QKeyEvent *e)
void glUpdateBackground()
void glCreateListLines(const VectorLine &aVectLine, unsigned int idList)
std::vector< typename Viewer3D< Space, KSpace >::CubeD3D > VectorCubes
double myLightR
the light position (azimuth)
RenderingMode myRenderingMode
const GLfloat myMetallicRenderDiff
void rotateDomain(Image2DDomainD3D &anDom, double angle, ImageDirection rotationDir)
void glCreateListQuadMaps(const typename Display3D< Space, KSpace >::QuadsMap &aQuadMap, unsigned int idList)
void glDrawGLBall(const typename Viewer3D< Space, KSpace >::BallD3D &aBall)
std::vector< typename Viewer3D< Space, KSpace >::LineD3D > VectorLine
GLfloat myMaterialSpecularCoeffs[4]
std::vector< Image2DDomainD3D > myImageDomainList
Used to store all the domains.
void updateRenderingCoefficients(const RenderingMode aRenderMode, bool displayState=true)
std::vector< typename Viewer3D< Space, KSpace >::PolygonD3D > VectorPolygon
bool myIsMovingLight
the reference mouse y-position used to determince the light position change (inclination)
std::vector< typename DGtal::Viewer3D< Space, KSpace >::LineD3D > compute2DDomainLineRepresentation(Image2DDomainD3D &anImageDomain)
std::vector< typename Viewer3D< Space, KSpace >::QuadD3D > VectorQuad
QPoint myPosSelector
a point selected with postSelection
void updateRelativeCameraFromLightPosition()
Display::RealPoint RealPoint
unsigned int myNbBallSetList
virtual unsigned int getCurrentDomainNumber()
virtual void initFromDOMElement(const QDomElement &element)
Overload of the QGLViewer method which restores the viewer state from a QDomDocument element....
GLuint myPolygonSetListId
const GLfloat myPlasticRenderDiff
const GLfloat myDefaultRenderDiff
void updateEmbeddingTextureImage(unsigned int anImageIndex, typename Space::Point aPoint1, typename Space::Point aPoint2, typename Space::Point aPoint3, typename Space::Point aPoint4)
const GLfloat myMetallicRenderSpec
double myGLLineMinWidth
to improve the display of gl points
void glCreateListCubesMaps(const typename Display3D< Space, KSpace >::CubesMap &aCubeMap, unsigned int idList)
void setGLLightSpecularCoefficients(const GLfloat lightSpecularCoeffs[4])
int myRefMouseYPos
the reference mouse x-position used to determince the light position change (azimuth)
std::vector< typename Viewer3D< Space, KSpace >::TextureImage > VectorTextureImage
GLuint myCubeSetListWiredId
int mySelectedElementId
used to displayed selected elements
void setGLScale(float sx, float sy, float sz)
void glCreateListBalls(const VectorBall &aVectBall, unsigned int idList)
unsigned int myNbPrismSetList
void glCreateListTrianglesWired(const std::vector< VectorTriangle > &aVectTriangle, unsigned int idList)
void updateOrientationTextureImage(unsigned int imageIndex, double xPosition, double yPosition, double zPosition, ImageDirection newDirection)
virtual void postSelection(const QPoint &point)
postSelection
GLfloat myMaterialShininessCoeff[1]
const GLfloat myLambertRenderDiff
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
DGtal::Color myDefaultBackgroundColor
the default background color of the viewer
void sortTriangleFromCamera()
void updateList(bool needToUpdateBoundingBox=true)
Display::SelectCallbackFct SelectCallbackFct
void glUpdateLightRenderingMode() const
ImageDirection
the 3 possible axes for the image direction
Display3D< Space, KSpace > Display
bool myUseGLPointsForBalls
unsigned int myNbListe
number of lists in myListToAff
GLuint myTriangleSetListWiredId
virtual void drawWithNames()
drawWithNames
void addTextureImage(const TextureImage &image)
GLfloat myLightPosition[4]
the light position (distance)
void setUseGLPointForBalls(bool useOpenGLPt)
std::vector< typename DGtal::Viewer3D< Space, KSpace >::LineD3D > compute2DDomainLineRepresentation(Image2DDomainD3D &anImageDomain, double delta)
void addImage2DDomainD3D(const TDomain &anImageDomain, std::string mode, const DGtal::Color &aColor=DGtal::Color::Red)
double myLightPhi
the light position (inclination)
double camera_position[3]
camera position
void setGLMaterialShininessCoefficient(const GLfloat matShininessCoeff)
void setGLLightAmbientCoefficients(const GLfloat lightAmbientCoeffs[4])
virtual void mouseReleaseEvent(QMouseEvent *e)
void glCreateListTriangles(const std::vector< VectorTriangle > &aVectTriangle, unsigned int idList)
double ZNear
znear distance
void glCreateListQuadD3D(const VectorQuad &aVectQuad, unsigned int idList)
Viewer3D< Space, KSpace > Self
void updateTextureImage(unsigned int imageIndex, const TImageType &image, const TFunctor &aFunctor, double xTranslation=0.0, double yTranslation=0.0, double zTranslation=0.0, double rotationAngle=0.0, ImageDirection rotationDir=zDirection)
void sortSurfelFromCamera()
void rotateLineD3D(typename DGtal::Display3D< Space, KSpace >::LineD3D &aLine, DGtal::PointVector< 3, int, TContainer > pt, double angleRotation, ImageDirection dirRotation)
double camera_direction[3]
camera direction
void setGLDoubleRenderingMode(bool doubleSidedRendering)
GLfloat myLightPositionRefCamera[3]
void setCameraUpVector(double ax, double ay, double az)
virtual QDomElement domElement(const QString &name, QDomDocument &document) const
Overload of the QGLViewer method which returns an XML QDomElement representing the QGLViewer state....
const GLfloat myDefaultRenderSpec
void updateLightCoordsFromCamera()
void glUpdateTextureImages(const VectorTextureImage &aVectImage)
std::vector< TextureImage > myGSImageList
flag to display the ligth source when it is moved by the user
Extension * myExtension
Stored a possible extension to the viewer (pointer owned).
T roundToUpperPowerOfTwo(const T &n)
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
RealPoint center
The center coordinate of the cube.
std::vector< RealPoint > vertices
bool operator()(typename Viewer3D< Space, KSpace >::PolygonD3D q1, typename Viewer3D< Space, KSpace >::PolygonD3D q2)
bool operator()(typename Viewer3D< Space, KSpace >::QuadD3D q1, typename Viewer3D< Space, KSpace >::QuadD3D q2)
bool operator()(typename Viewer3D< Space, KSpace >::TriangleD3D t1, typename Viewer3D< Space, KSpace >::TriangleD3D t2)
bool operator()(typename Viewer3D< Space, KSpace >::CubeD3D s1, typename Viewer3D< Space, KSpace >::CubeD3D s2)
virtual bool mouseMoveEvent(const Viewer &viewer, QMouseEvent *event)
virtual ~Extension()=default
virtual QString helpString(const Viewer &viewer) const
virtual void draw(Viewer &viewer)
virtual bool mouseReleaseEvent(const Viewer &viewer, QMouseEvent *event)
virtual bool mousePressEvent(const Viewer &viewer, QMouseEvent *event)
virtual bool postSelection(const Viewer &viewer, const QPoint &point)
virtual void drawWithNames(Viewer &viewer)
virtual void init(Viewer &viewer)
virtual bool keyPressEvent(Viewer &viewer, QKeyEvent *event)
Viewer3D< Space, KSpace > Viewer
The associated viewer.
unsigned int myBufferHeight
unsigned char * myTextureImageBufferGS
GLTextureImage(const GLTextureImage &aGLImg)
unsigned int myImageWidth
GLTextureImage(const typename Viewer3D< Space, KSpace >::TextureImage &aGSImage)
unsigned int myBufferWidth
unsigned char * myTextureImageBufferRGB
Viewer3D< Space, KSpace >::ImageDirection myDirection
RealPoint point1
coordinates
Viewer3D< Space, KSpace >::TextureMode myMode
unsigned int myImageHeight
unsigned int myDomainWidth
the width of the image domain
Image2DDomainD3D(TDomain aDomain, ImageDirection normalDir=zDirection, double xBottomLeft=0.0, double yBottomLeft=0.0, double zBottomLeft=0.0, std::string mode="BoundingBox")
unsigned int myDomainHeight
the height of the image domain
ImageDirection myDirection
the direction of the domain (x, y or z axe)
DGtal::Color color
The image domain color.
std::size_t myLineSetIndex
the index of the line of the domain in the lineSetList of the viewer
void translateDomain(double xTranslation=0.0, double yTranslation=0.0, double zTranslation=0.0)
RealPoint point1
The image domain coordinates.
std::string myMode
the mode of representation of the image domain
void updateDomainOrientation(ImageDirection normalDir, double xBottomLeft, double yBottomLeft, double zBottomLeft)
unsigned int myImageHeight
the width of the image
void updateImageOrientation(ImageDirection normalDir, double xBottomLeft, double yBottomLeft, double zBottomLeft)
unsigned int * myTabImage
the height of the image
TextureImage(const TImageType &image, const TFunctor &aFunctor, ImageDirection normalDir=zDirection, double xBottomLeft=0.0, double yBottomLeft=0.0, double zBottomLeft=0.0, TextureMode aMode=GrayScaleMode)
bool myDrawDomain
for each pixel of the image, color or height ?
ImageDirection myDirection
~TextureImage()
the mode of representation of the image
TextureMode myMode
index of the image domain if exist
TextureImage(const TextureImage &img)
Copy constructor (needed due to myTabImage)
void updateImageDataAndParam(const TImageType &image, const TFunctor &aFunctor, double xTranslation=0.0, double yTranslation=0.0, double zTranslation=0.0)
unsigned int myImageWidth
direction of the image (x, y or z axe)
std::string className() const
unsigned int myIndexDomain
true if the draw have a domain
void updateImage3DEmbedding(RealPoint aPoint1, RealPoint aPoint2, RealPoint aPoint3, RealPoint aPoint4)
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Aim: Defines a unary functor, which associates arguments to results.