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
55 #include <OpenGL/gl.h>
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));
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 displayMessage(QString(
"Light source position fixed to camera."), 3000);
986 displayMessage(QString(
"Light source position fixed to main scene."), 3000);
1002 QGLViewer::drawLight( light );
1007 QGLViewer::drawLight( light, zoom );
1077 sqrt( (
posCam.x - s1.center[ 0 ] ) * (
posCam.x - s1.center[ 0 ] ) +
1078 (
posCam.y - s1.center[ 1 ] ) * (
posCam.y - s1.center[ 1 ] ) +
1079 (
posCam.z - s1.center[ 2 ] ) * (
posCam.z - s1.center[ 2 ] ) );
1081 sqrt( (
posCam.x - s2.center[ 0 ] ) * (
posCam.x - s2.center[ 0 ] ) +
1082 (
posCam.y - s2.center[ 1 ] ) * (
posCam.y - s2.center[ 1 ] ) +
1083 (
posCam.z - s2.center[ 2 ] ) * (
posCam.z - s2.center[ 2 ] ) );
1084 return dist1 > dist2;
1098 qglviewer::Vec center1 ( ( t1.point1[0]+t1.point2[0]+t1.point3[0] ) /3.0, ( t1.point1[1]+t1.point2[1]+t1.point3[1] ) /3.0, ( t1.point1[2]+t1.point2[2]+t1.point3[2] ) /3.0 );
1099 qglviewer::Vec center2 ( ( t2.point1[0]+t2.point2[0]+t2.point3[0] ) /3.0, ( t2.point1[1]+t2.point2[1]+t2.point3[1] ) /3.0, ( t2.point1[2]+t2.point2[2]+t2.point3[2] ) /3.0 );
1117 qglviewer::Vec center1 ( ( q1.point1[0]+q1.point2[0]+q1.point3[0]+q1.point4[0] ) /4.0, ( q1.point1[1]+q1.point2[1]+q1.point3[1]+q1.point4[1] ) /4.0, ( q1.point1[2]+q1.point2[2]+q1.point3[2]+q1.point4[2] ) /4.0 );
1118 qglviewer::Vec center2 ( ( q2.point1[0]+q2.point2[0]+q2.point3[0]+q2.point4[0] ) /4.0, ( q2.point1[1]+q2.point2[1]+q2.point3[1]+q2.point4[1] ) /4.0, ( q2.point1[2]+q2.point2[2]+q2.point3[2]+q2.point4[2] ) /4.0 );
1135 double c1x=0.0, c1y=0.0, c1z=0.0;
1136 double c2x=0.0, c2y=0.0, c2z=0.0;
1137 for(
unsigned int i=0; i< q1.vertices.size(); i++){
1138 c1x+=q1.vertices.at(i)[0];
1139 c1y+=q1.vertices.at(i)[1];
1140 c1z+=q1.vertices.at(i)[2];
1142 for(
unsigned int i=0; i< q2.vertices.size(); i++){
1143 c2x+=q2.vertices.at(i)[0];
1144 c2y+=q2.vertices.at(i)[1];
1145 c2z+=q2.vertices.at(i)[2];
1148 qglviewer::Vec center1 ( c1x/(
double)q1.vertices.size(),c1y/(
double)q1.vertices.size(), c1z/(
double)q1.vertices.size() );
1149 qglviewer::Vec center2 ( c2x/(
double)q2.vertices.size(),c2y/(
double)q2.vertices.size(), c2z/(
double)q2.vertices.size() );
1196 virtual QDomElement
domElement(
const QString& name, QDomDocument& document)
const;
1315 point1[0]=aGSImage.point1[0];
point1[1]=aGSImage.point1[1];
point1[2]=aGSImage.point1[2];
1316 point2[0]=aGSImage.point2[0];
point2[1]=aGSImage.point2[1];
point2[2]=aGSImage.point2[2];
1317 point3[0]=aGSImage.point3[0];
point3[1]=aGSImage.point3[1];
point3[2]=aGSImage.point3[2];
1318 point4[0]=aGSImage.point4[0];
point4[1]=aGSImage.point4[1];
point4[2]=aGSImage.point4[2];
1391 typedef typename std::vector<typename Viewer3D<Space, KSpace>::CubeD3D>
VectorCubes;
1392 typedef typename std::vector<typename Viewer3D<Space, KSpace>::QuadD3D>
VectorQuad;
1393 typedef typename std::vector<typename Viewer3D<Space, KSpace>::LineD3D>
VectorLine;
1394 typedef typename std::vector<typename Viewer3D<Space, KSpace>::BallD3D>
VectorBall;
1395 typedef typename std::vector<typename Viewer3D<Space, KSpace>::TriangleD3D>
VectorTriangle;
1396 typedef typename std::vector<typename Viewer3D<Space, KSpace>::PolygonD3D>
VectorPolygon;
1400 typedef typename VectorCubes::iterator
ItCube;
1560 template<
typename TImageORDomain>
1564 double xB = (anImageOrDom.point1[0]+anImageOrDom.point2[0]+anImageOrDom.point3[0]+anImageOrDom.point4[0])/4.0;
1565 double yB = (anImageOrDom.point1[1]+anImageOrDom.point2[1]+anImageOrDom.point3[1]+anImageOrDom.point4[1])/4.0;
1566 double zB = (anImageOrDom.point1[2]+anImageOrDom.point2[2]+anImageOrDom.point3[2]+anImageOrDom.point4[2])/4.0;
1567 rotatePoint( anImageOrDom.point1[0], anImageOrDom.point1[1], anImageOrDom.point1[2], xB, yB, zB, angle, rotationDir);
1568 rotatePoint( anImageOrDom.point2[0], anImageOrDom.point2[1], anImageOrDom.point2[2], xB, yB, zB, angle, rotationDir);
1569 rotatePoint( anImageOrDom.point3[0], anImageOrDom.point3[1], anImageOrDom.point3[2], xB, yB, zB, angle, rotationDir);
1570 rotatePoint( anImageOrDom.point4[0], anImageOrDom.point4[1], anImageOrDom.point4[2], xB, yB, zB, angle, rotationDir);
1587 template <
typename TValues>
1590 double cx,
double cy,
double cz,
1693 template <
typename TSpace,
typename TKSpace>
1707 #include "DGtal/io/viewers/Viewer3D.ih"
1714 #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.
SelectCallbackFct getSelectCallback3D(DGtal::int32_t aName, void *&data) const
Space::RealPoint RealPoint
RealPoint type.
Aim: Implements basic operations that will be used in Point and Vector classes.
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)
Viewer3D< Space, KSpace > & operator<<(const DGtal::Color &aColor)
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 DGtal::Viewer3D< Space, KSpace >::LineD3D > compute2DDomainLineRepresentation(Image2DDomainD3D &anImageDomain, double delta)
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 Viewer3D< Space, KSpace >::QuadD3D > VectorQuad
QPoint myPosSelector
a point selected with postSelection
void updateRelativeCameraFromLightPosition()
void setLightModeFixToCamera(bool fixedToCam, bool verbose=true)
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)
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()
std::vector< typename DGtal::Viewer3D< Space, KSpace >::LineD3D > compute2DDomainLineRepresentation(Image2DDomainD3D &anImageDomain)
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).
MyDigitalSurface::ConstIterator ConstIterator
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 ATu0v1< TKSpace, TLinearAlgebra > &object)
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
Viewer3D< Space, KSpace >::ImageDirection myDirection
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 >::TextureMode myMode
RealPoint point1
coordinates
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 read-only image, which is a refinement of CPointFunctor.
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
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.