DGtal 1.3.0
Loading...
Searching...
No Matches
Display3D.h
1
17#pragma once
18
31#if defined(Display3D_RECURSES)
32#error Recursive header files inclusion detected in Display3D.h
33#else // defined(Display3D_RECURSES)
35#define Display3D_RECURSES
36
37#if !defined Display3D_h
39#define Display3D_h
40
42// Inclusions
43#include <iostream>
44#include <vector>
45#include <algorithm>
46#include <map>
47#include "DGtal/kernel/domains/CDomain.h"
48#include "DGtal/base/Common.h"
49#include "DGtal/base/CountedPtr.h"
50#include "DGtal/io/Color.h"
51#include "DGtal/images/CImage.h"
52#include "DGtal/images/CConstImage.h"
53#include "DGtal/shapes/Mesh.h"
54
56#include "DGtal/topology/CanonicCellEmbedder.h"
57#include "DGtal/topology/CanonicSCellEmbedder.h"
58#include "DGtal/kernel/CanonicEmbedder.h"
59#include "DGtal/helpers/StdDefs.h"
60#include "DGtal/io/DrawWithDisplay3DModifier.h"
61#include "DGtal/kernel/CSpace.h"
62
63
65
66
67namespace DGtal
68{
69
71 // class Display3D
91 template < typename Space = Z3i::Space, typename KSpace = Z3i::KSpace>
93 {
94 public:
95
97 public:
98
101 typedef typename Space::RealPoint RealPoint;
107
109 typedef int (*SelectCallbackFct)( void* viewer, DGtal::int32_t name, void* data );
110
111 protected:
112
118 SelectCallbackFctStore( SelectCallbackFct _fct,
119 void* _data,
120 DGtal::int32_t _min, DGtal::int32_t _max )
121 : fct( _fct ), data( _data ), min( _min ), max( _max ) {}
122 bool operator<( const SelectCallbackFctStore& other ) const
123 {
124 return ( min < other.min ); // simple since there is no overlap.
125 }
126 bool isSelected( DGtal::int32_t name ) const
127 { return ( min <= name ) && ( name <= max ); }
128
129 SelectCallbackFct fct;
130 void* data;
133 };
134
138 struct CommonD3D {
141
142 protected:
143 ~CommonD3D() = default;
144 };
145
149 struct LineD3D : public CommonD3D {
152 double width;
155 };
156
160 struct CubeD3D : public CommonD3D {
164 double width;
165 };
166
173 struct ClippingPlaneD3D : public CommonD3D {
174 double a,b,c,d;
175 };
176
177
185 struct QuadD3D : public CommonD3D {
190 double nx, ny, nz;
191 };
192
193
194
200 struct TriangleD3D : public CommonD3D {
204 double nx, ny, nz;
205 };
206
207
208 public:
209
210
211
215 //have to be public because of external functions
216 struct BallD3D : public CommonD3D
217 {
219 const double & operator[]( unsigned int i ) const
220 {
221 assert(i<3);
222 return center[i];
223 };
224 double & operator[]( unsigned int i )
225 {
226 assert(i<3);
227 return center[i];
228 };
232 double radius;
233 unsigned int resolution;
234 };
235
236
241 struct PolygonD3D : public CommonD3D
242 {
243 std::vector<RealPoint> vertices;
244 double nx, ny, nz;
246 };
247
248
250
251
252 public:
254 typedef std::map<DGtal::int32_t, std::vector< QuadD3D > > QuadsMap;
255
257 typedef std::map<DGtal::int32_t, std::vector< CubeD3D > > CubesMap;
258
259
260 protected:
269
270
271
272
273 //----end of private data
274
275 // ----------------------- Standard services ------------------------------
276 public:
277
281 virtual ~Display3D()
282 {
283 delete myEmbedder;
284 delete mySCellEmbedder;
285 delete myCellEmbedder;
286 }
287
292 Display3D( const KSpace & KSEmb )
293 : myKSpace( KSEmb )
294 , myEmbedder( new Embedder() )
297 , myBoundingPtEmptyTag( true )
298 , myCurrentFillColor( 220, 220, 220 )
299 , myCurrentLineColor( 22, 22, 222, 50 )
300 {
301 }
302
308 : Display3D( KSpace() )
309 {
310 }
311
313 Display3D( const Display3D & ) = delete;
314
316 Display3D( Display3D && ) = delete;
317
319 Display3D & operator= ( const Display3D & ) = delete;
320
323
324 // ----------------------- Interface --------------------------------------
325 public:
326
328 const Embedder& embedder() const
329 { return *myEmbedder; }
330
333 { return *myCellEmbedder; }
334
337 { return *mySCellEmbedder; }
338
340 const KSpace& space() const
341 { return myKSpace; }
342
347 virtual void setFillColor(DGtal::Color aColor);
348
353 virtual void setFillTransparency(unsigned char alpha);
354
355
360 virtual void setLineColor(DGtal::Color aColor);
361
362
369
376
381 virtual void setKSpace( const KSpace & aKSpace );
382
383
388 void setName3d( DGtal::int32_t name = -1 );
389
394
406 void setSelectCallback3D( SelectCallbackFct fct, void* data,
407 DGtal::int32_t min_name, DGtal::int32_t max_name );
408
415 SelectCallbackFct getSelectCallback3D( DGtal::int32_t aName, void*& data ) const;
416
417 // ----------------------- Graphical directives ----------------------------------
418 public:
419
420
432 void addClippingPlane(double a, double b, double c, double d, bool drawPlane);
433
434
435
436
444 std::string getMode( const std::string & objectName ) const;
445
451 void createNewLineList(std::string s= "");
452
453
459 void createNewBallList(std::string s= "");
460
461
469
470
478
485
486
494
500 void createNewTriangleList(std::string s= "");
501
507 void createNewPolygonList(std::string s= "");
508
509
521 void addQuad(const RealPoint &p1, const RealPoint &p2,
522 const RealPoint &p3, const RealPoint &p4);
523
542 void addQuadWithNormal(const RealPoint &p1, const RealPoint &p2,
543 const RealPoint &p3, const RealPoint &p4,
544 const RealPoint &n,
545 const bool enableReorientation,
546 const bool enableDoubleFace = false);
547
557 void addQuadFromSurfelCenter(const RealPoint &baseQuadCenter,
558 bool xSurfel, bool ySurfel, bool zSurfel);
559
560
561
584 void addQuadFromSurfelCenterWithNormal(const RealPoint &baseQuadCenter, bool xSurfel, bool ySurfel, bool zSurfel,
585 const RealVector &aNormal,
586 const bool enableReorientation,
587 const bool sign,
588 const bool enableDoubleFace = false);
589
590
597 void addTriangle(const RealPoint &p1, const RealPoint &p2, const RealPoint &p3);
598
599
604 void addPolygon(const std::vector<RealPoint> &vertices);
605
606
616 void addLine(const RealPoint &p1, const RealPoint &p2, const double width=0.03);
617
618
626 void addCube(const RealPoint &center, double width=1.0);
627
628
636 void addBall(const RealPoint &center ,
637 const double radius=0.5,
638 const unsigned int resolution = 30);
639
640
641
655 void addPrism(const RealPoint &baseQuadCenter,
656 bool xSurfel, bool ySurfel, bool zSurfel, double sizeShiftFactor,
657 double sizeFactor=1.0, bool isSigned= false, bool aSign=true);
658
659
660
669 void addBasicSurfel(const RealPoint &baseQuadCenter,
670 bool xSurfel, bool ySurfel, bool zSurfel);
671
672
680 void addCone(const RealPoint &p1, const RealPoint &p2,
681 double width=0.08);
682
683
690 void addCylinder(const RealPoint &p1, const RealPoint &p2,
691 const double width=0.02);
692
693
699 void updateBoundingBox(const RealPoint &point);
700
701
702
703
710 void exportToMesh(Mesh<RealPoint> & aMesh ) const;
711
712
721 template <typename TDrawableWithDisplay3D>
722 Display3D & operator<<( const TDrawableWithDisplay3D & object );
723
724
725
730 void selfDisplay ( std::ostream & out ) const;
731
732
737 bool isValid() const;
738
739
743 void clear();
744
745
746
752 RealPoint embed(const typename Space::Point & dp) const ;
753
759 RealPoint embedKS( const typename KSpace::SCell & cell ) const;
760
761
768
769
775 RealPoint embedK( const typename KSpace::Cell & cell ) const;
776
777 //---end interface
778
779 // ------------------------- Protected Datas ------------------------------
780 public:
781
786 typedef std::map< std::string, std::string > ModeMapping;
787
792 typedef std::map< std::string,CountedPtr<DrawableWithDisplay3D> > StyleMapping;
793
794
807
811 double myBoundingPtUp [3];
813 double myBoundingPtLow [3];
814
815 protected:
816 //the current fill color of the display
818 //the current line color of the display
820
824
827 std::vector< std::vector<LineD3D> > myLineSetList;
828
831 std::vector< std::vector<BallD3D> > myBallSetList;
832
835 std::vector< ClippingPlaneD3D > myClippingPlaneList;
836
839 std::vector< QuadD3D > myPrismList;
840
846
848 std::vector<std::vector< TriangleD3D > > myTriangleSetList;
849
851 std::vector<std::vector<PolygonD3D> > myPolygonSetList;
852
853
858
859
862 std::vector<std::string> myCubeSetNameList;
863
866 std::vector<std::string> myLineSetNameList;
867
870 std::vector<std::string> myBallSetNameList;
873 std::vector<std::string> myClippingPlaneNameList;
874
877 std::vector<std::string> myPrismNameList;
878
881 std::vector<std::string> myQuadSetNameList;
882
885 std::vector<std::string> myTriangleSetNameList;
886
889 std::vector<std::string> myPolygonSetNameList;
890
894
897 std::set<SelectCallbackFctStore> mySelectCallBackFcts;
898
900
901 //----end of protected datas
902
903 // ------------------------- Internals ------------------------------------
904 protected:
905
912 static void cross (double dst[3], double srcA[3], double srcB[3]);
913
918 static void normalize (double vec[3]);
919
920
921 }; // end of class Display3D
922
929 template <typename Space , typename KSpace >
930 std::ostream&
931 operator<< ( std::ostream & out, const DGtal::Display3D<Space , KSpace > & object );
932
933
934 template <typename Space , typename KSpace >
941 void
944
945
952 template < typename Space , typename KSpace >
953 void
954 operator>> ( const Display3D< Space , KSpace > &aDisplay3D, std::string aFilename);
955
956
957} // namespace DGtal
958
959
961// Includes inline functions.
962#include "DGtal/io/Display3D.ih"
963
964
965// //
967
968#endif // !defined Display3D_h
969
970#undef Display3D_RECURSES
971#endif // else defined(Display3D_RECURSES)
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: This semi abstract class defines the stream mechanism to display 3d primitive (like BallVector,...
Definition: Display3D.h:93
virtual DGtal::Color getLineColor()
std::set< SelectCallbackFctStore > mySelectCallBackFcts
Definition: Display3D.h:897
RealPoint embedKS(const typename KSpace::SCell &cell) const
SCellEmbedder * mySCellEmbedder
an embeder from a signed khalimsky space point to a real space point
Definition: Display3D.h:268
Display3D< Space, KSpace > Self
Definition: Display3D.h:99
QuadsMap myQuadsMap
Definition: Display3D.h:845
std::vector< std::string > myQuadSetNameList
Definition: Display3D.h:881
void createNewTriangleList(std::string s="")
void createNewLineList(std::string s="")
const CellEmbedder & cellEmbedder() const
Definition: Display3D.h:332
std::vector< std::vector< PolygonD3D > > myPolygonSetList
Represents all the polygon drawn in the Display3D.
Definition: Display3D.h:851
DGtal::int32_t createNewQuadList()
void addCylinder(const RealPoint &p1, const RealPoint &p2, const double width=0.02)
virtual void setLineColor(DGtal::Color aColor)
DGtal::int32_t createNewCubeList()
CanonicSCellEmbedder< KSpace > SCellEmbedder
Definition: Display3D.h:106
std::vector< std::string > myLineSetNameList
Definition: Display3D.h:866
std::map< std::string, std::string > ModeMapping
Definition: Display3D.h:786
std::vector< ClippingPlaneD3D > myClippingPlaneList
Definition: Display3D.h:835
bool deleteQuadList(const DGtal::int32_t name)
const KSpace & space() const
Definition: Display3D.h:340
std::vector< std::vector< TriangleD3D > > myTriangleSetList
Represents all the triangles drawn in the Display3D.
Definition: Display3D.h:848
static void normalize(double vec[3])
KSpace myKSpace
The Khalimsky space.
Definition: Display3D.h:262
CanonicCellEmbedder< KSpace > CellEmbedder
Definition: Display3D.h:105
Display3D & operator=(const Display3D &)=delete
Assignment operator. Deleted.
void addPrism(const RealPoint &baseQuadCenter, bool xSurfel, bool ySurfel, bool zSurfel, double sizeShiftFactor, double sizeFactor=1.0, bool isSigned=false, bool aSign=true)
const SCellEmbedder & sCellEmbedder() const
Definition: Display3D.h:336
void updateBoundingBox(const RealPoint &point)
virtual DGtal::Color getFillColor()
BOOST_CONCEPT_ASSERT((concepts::CSpace< Space >))
std::vector< std::vector< BallD3D > > myBallSetList
Definition: Display3D.h:831
bool myBoundingPtEmptyTag
True if the bounding box is empty (no objects added)
Definition: Display3D.h:809
std::map< DGtal::int32_t, std::vector< CubeD3D > > CubesMap
The type that maps identifier name -> vector of CubeD3D.
Definition: Display3D.h:257
void addQuadFromSurfelCenterWithNormal(const RealPoint &baseQuadCenter, bool xSurfel, bool ySurfel, bool zSurfel, const RealVector &aNormal, const bool enableReorientation, const bool sign, const bool enableDoubleFace=false)
DGtal::Color myCurrentFillColor
Definition: Display3D.h:817
std::vector< QuadD3D > myPrismList
Definition: Display3D.h:839
CubesMap myCubesMap
Definition: Display3D.h:857
RealPoint embedK(const typename KSpace::Cell &cell) const
std::map< std::string, CountedPtr< DrawableWithDisplay3D > > StyleMapping
Definition: Display3D.h:792
virtual void setFillColor(DGtal::Color aColor)
SelectCallbackFct getSelectCallback3D(DGtal::int32_t aName, void *&data) const
void addQuadFromSurfelCenter(const RealPoint &baseQuadCenter, bool xSurfel, bool ySurfel, bool zSurfel)
void exportToMesh(Mesh< RealPoint > &aMesh) const
bool isValid() const
RealPoint embed(const typename Space::Point &dp) const
std::vector< std::string > myPrismNameList
Definition: Display3D.h:877
virtual void setKSpace(const KSpace &aKSpace)
std::map< DGtal::int32_t, std::vector< QuadD3D > > QuadsMap
The type that maps identifier name -> vector of QuadD3D.
Definition: Display3D.h:254
void addLine(const RealPoint &p1, const RealPoint &p2, const double width=0.03)
void setSelectCallback3D(SelectCallbackFct fct, void *data, DGtal::int32_t min_name, DGtal::int32_t max_name)
void setName3d(DGtal::int32_t name=-1)
std::vector< std::string > myBallSetNameList
Definition: Display3D.h:870
void addCube(const RealPoint &center, double width=1.0)
std::vector< std::string > myPolygonSetNameList
Definition: Display3D.h:889
void addQuadWithNormal(const RealPoint &p1, const RealPoint &p2, const RealPoint &p3, const RealPoint &p4, const RealPoint &n, const bool enableReorientation, const bool enableDoubleFace=false)
double myCurrentfShiftVisuPrisms
Definition: Display3D.h:823
void addPolygon(const std::vector< RealPoint > &vertices)
DGtal::int32_t name3d() const
void createNewBallList(std::string s="")
Display3D(const Display3D &)=delete
Copy constructor. Deleted.
void addBall(const RealPoint &center, const double radius=0.5, const unsigned int resolution=30)
std::vector< std::string > myCubeSetNameList
Definition: Display3D.h:862
void addTriangle(const RealPoint &p1, const RealPoint &p2, const RealPoint &p3)
Display3D(const KSpace &KSEmb)
Definition: Display3D.h:292
Embedder * myEmbedder
an embeder from a dgtal space point to a real space point
Definition: Display3D.h:264
double myBoundingPtUp[3]
upper point of the bounding box
Definition: Display3D.h:811
CellEmbedder * myCellEmbedder
an embeder from a unsigned khalimsky space point to a real space point
Definition: Display3D.h:266
void addClippingPlane(double a, double b, double c, double d, bool drawPlane)
Space::RealPoint RealPoint
RealPoint type.
Definition: Display3D.h:101
bool myBoundingPtChangedTag
Definition: Display3D.h:899
virtual ~Display3D()
Definition: Display3D.h:281
const Embedder & embedder() const
Definition: Display3D.h:328
std::vector< std::string > myTriangleSetNameList
Definition: Display3D.h:885
void addQuad(const RealPoint &p1, const RealPoint &p2, const RealPoint &p3, const RealPoint &p4)
DGtal::Color myCurrentLineColor
Definition: Display3D.h:819
CanonicEmbedder< Space > Embedder
Definition: Display3D.h:104
std::string getMode(const std::string &objectName) const
DGtal::int32_t myName3d
Definition: Display3D.h:893
bool deleteCubeList(const DGtal::int32_t name)
double myBoundingPtLow[3]
lower point of the bouding box
Definition: Display3D.h:813
std::vector< std::string > myClippingPlaneNameList
Definition: Display3D.h:873
void createNewPolygonList(std::string s="")
Display3D & operator<<(const TDrawableWithDisplay3D &object)
void selfDisplay(std::ostream &out) const
Display3D(Display3D &&)=delete
Move constructor. Deleted.
RealPoint embedKS(const DGtal::TransformedPrism &aTrans) const
ModeMapping myModes
Definition: Display3D.h:795
void addCone(const RealPoint &p1, const RealPoint &p2, double width=0.08)
void addBasicSurfel(const RealPoint &baseQuadCenter, bool xSurfel, bool ySurfel, bool zSurfel)
virtual void setFillTransparency(unsigned char alpha)
Space::RealVector RealVector
RealVector type.
Definition: Display3D.h:103
StyleMapping myStyles
Definition: Display3D.h:806
static void cross(double dst[3], double srcA[3], double srcB[3])
std::vector< std::vector< LineD3D > > myLineSetList
Definition: Display3D.h:827
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
Definition: Mesh.h:92
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
DGtal::Dimension Dimension
Copy of the dimension type.
Definition: PointVector.h:623
static const Dimension dimension
Copy of the static dimension of the Point/Vector.
Definition: PointVector.h:626
PointVector< dim, double > RealPoint
Definition: SpaceND.h:117
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
void operator>>(const Display3D< Space, KSpace > &aDisplay3D, DGtal::Mesh< typename Display3D< Space, KSpace >::RealPoint > &aMesh)
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
Aim: A trivial embedder for signed and unsigned cell, which corresponds to the canonic injection of c...
Aim: A trivial embedder for digital points, which corresponds to the canonic injection of Zn into Rn.
Aim: A trivial embedder for signed cell, which corresponds to the canonic injection of cell centroids...
const double & operator[](unsigned int i) const
Definition: Display3D.h:219
unsigned int resolution
Definition: Display3D.h:233
double & operator[](unsigned int i)
Definition: Display3D.h:224
static const RealPoint::Dimension dimension
Definition: Display3D.h:218
DGtal::int32_t name
The "OpenGL name" associated with the graphical structure, used for selecting it (-1 is none).
Definition: Display3D.h:140
~CommonD3D()=default
Protected destructor to disallow polymorphism.
DGtal::Color color
Color used for displaying the graphical structure.
Definition: Display3D.h:139
RealPoint center
The center coordinate of the cube.
Definition: Display3D.h:162
double width
The width of a cube face.
Definition: Display3D.h:164
std::vector< RealPoint > vertices
Definition: Display3D.h:243
bool operator<(const SelectCallbackFctStore &other) const
Definition: Display3D.h:122
bool isSelected(DGtal::int32_t name) const
Definition: Display3D.h:126
SelectCallbackFctStore(SelectCallbackFct _fct, void *_data, DGtal::int32_t _min, DGtal::int32_t _max)
Definition: Display3D.h:118
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
class to modify the position and scale to construct better illustration mode.
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:106