diff --git a/ChangeLog.md b/ChangeLog.md index 93ea12a8b8..a961efa259 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,20 +2,21 @@ ## New Features / Critical Changes +## Changes + +- *Math package* + - New SimpleMatrix constructor with a initializer_list argument +   (Nicolas Normand, + [#1250](https://github.com/DGtal-team/DGtal/pull/1250)) - *IO* - New simple way to extend the QGLViewer-based Viewer3D interface, for instance to add callbacks to key or mouse events, or to modify what is drawn on the window. (Jacques-Olivier Lachaud, [#1259](https://github.com/DGtal-team/DGtal/pull/1259)) - -## Changes - -- *IO* - - TableReader can now read all elements contained in each line of a file + - TableReader can now read all elements contained in each line of a file with the new method getLinesElementsFromFile(). (Bertrand Kerautret, [#1260](https://github.com/DGtal-team/DGtal/pull/1260)) - ## Bug Fixes - *Shapes Package* @@ -37,10 +38,10 @@ handle 32/16 bits images. Also includes a new testITKReader and ITK tests in GenericReader. (Bertrand Kerautret, [#1255](https://github.com/DGtal-team/DGtal/pull/1255)) - - Viewer3D: fix bad light source move according X/Y mouse move and new Key_Z to + - Viewer3D: fix bad light source move according X/Y mouse move and new Key_Z to move away/closer the light source. (Bertrand Kerautret, [#1262](https://github.com/DGtal-team/DGtal/pull/1262)) - + - *Kernel Package* - Fix testBasicPointFunctor. (Bertrand Kerautret [#1245](https://github.com/DGtal-team/DGtal/pull/1245)) @@ -52,7 +53,7 @@ was also added to the generic readers when ITK is present (Bertrand Kerautret [1251](https://github.com/DGtal-team/DGtal/pull/1245)) - Fix exampleArithDSS3d compilation (which was not activated). - (Bertrand Kerautret + (Bertrand Kerautret [#1254](https://github.com/DGtal-team/DGtal/pull/1254)) # DGtal 0.9.3 diff --git a/examples/geometry/curves/exampleArithDSS3d.cpp b/examples/geometry/curves/exampleArithDSS3d.cpp index 863072f096..f672791467 100644 --- a/examples/geometry/curves/exampleArithDSS3d.cpp +++ b/examples/geometry/curves/exampleArithDSS3d.cpp @@ -48,7 +48,7 @@ #include #include "DGtal/io/viewers/Viewer3D.h" -#ifdef WITH_CAIRO +#ifdef WITH_CAIRO #include "DGtal/io/boards/Board3DTo2D.h" #endif diff --git a/examples/io/viewers/viewer3D-11-extension.cpp b/examples/io/viewers/viewer3D-11-extension.cpp index e1a2bcc566..7c2cfb2607 100644 --- a/examples/io/viewers/viewer3D-11-extension.cpp +++ b/examples/io/viewers/viewer3D-11-extension.cpp @@ -34,7 +34,8 @@ * * @see moduleQGLExtension * \example io/viewers/viewer3D-11-extension.cpp - * \image html simple3dVisu1.png "Extending the Viewer3D interface: just press Shift+R and you have new points added randomly in the scene." + * \image html simple3dVisu1.png "Extending the Viewer3D interface: just press + * Shift+R and you have new points added randomly in the scene." */ /////////////////////////////////////////////////////////////////////////////// @@ -49,84 +50,82 @@ using namespace std; using namespace DGtal; using namespace Z3i; - /////////////////////////////////////////////////////////////////////////////// // Standard services - public : - //! [viewer3D-extension-derivation] // Deriving from Viewer3D::Extension to add new callbacks to events. -struct RandomPointKeyExtension : public Viewer3D::Extension +struct RandomPointKeyExtension : public Viewer3D::Extension { - RandomPointKeyExtension() {} + RandomPointKeyExtension() + { + } // Here we override the "key pressed" event, and a point randomly in // the scene if the key "Shift+R" is pressed. - virtual bool keyPressEvent ( Viewer& viewer, QKeyEvent * event ) + virtual bool keyPressEvent( Viewer & viewer, QKeyEvent * event ) { bool handled = false; // Get event modifiers key const Qt::KeyboardModifiers modifiers = event->modifiers(); - if( ( event->key() == Qt::Key_R ) && ( modifiers == Qt::ShiftModifier ) ) - { - typedef Viewer::KSpace KSpace; - Point p = viewer.space().lowerBound(); - Point q = viewer.space().upperBound(); - Point d = q - p; - Point a( ( rand() % d[ 0 ] ) + p[ 0 ], - ( rand() % d[ 1 ] ) + p[ 1 ], - ( rand() % d[ 2 ] ) + p[ 2 ] ); - viewer << a; - viewer << Viewer::updateDisplay; - trace.info() << "Adding point " << a << std::endl; - handled = true; - } + if ( ( event->key() == Qt::Key_R ) && ( modifiers == Qt::ShiftModifier ) ) + { + typedef Viewer::KSpace KSpace; + Point p = viewer.space().lowerBound(); + Point q = viewer.space().upperBound(); + Point d = q - p; + Point a( ( rand() % d[ 0 ] ) + p[ 0 ], ( rand() % d[ 1 ] ) + p[ 1 ], + ( rand() % d[ 2 ] ) + p[ 2 ] ); + viewer << a; + viewer << Viewer::updateDisplay; + trace.info() << "Adding point " << a << std::endl; + handled = true; + } return handled; } // We also override the Viewer3D::init method to add a key // description in the help window. - virtual void init( Viewer& viewer ) + virtual void init( Viewer & viewer ) { - viewer.setKeyDescription ( Qt::ShiftModifier+Qt::Key_R, - "Creates a random digital point." ); + viewer.setKeyDescription( Qt::ShiftModifier + Qt::Key_R, + "Creates a random digital point." ); } // We also override the Viewer3D::helpString method to add a // description to the viewer. - virtual QString helpString(const Viewer& viewer) const + virtual QString helpString( const Viewer & viewer ) const { QString text( "

Random point Viewer3D

" ); text += "Press Shift+R to add points."; return text; } - }; //! [viewer3D-extension-derivation] -int main( int argc, char** argv ) +int main( int argc, char ** argv ) { - QApplication application(argc,argv); - - Point p1( 0, 0, 0 ); - Point p2( 5, 5 ,5 ); - Point p3( 2, 3, 4 ); - Domain domain( p1, p2 ); - - typedef Viewer3D<> MyViewer; - KSpace K; - K.init( p1, p2, true ); - //! [viewer3D-extension-set-extension] - MyViewer viewer( K ); - viewer.setExtension( new RandomPointKeyExtension ); - //! [viewer3D-extension-set-extension] - viewer.show(); - viewer << domain; - viewer << p1 << p2 << p3; - - viewer<< MyViewer::updateDisplay; - return application.exec(); + QApplication application( argc, argv ); + + Point p1( 0, 0, 0 ); + Point p2( 5, 5, 5 ); + Point p3( 2, 3, 4 ); + Domain domain( p1, p2 ); + + typedef Viewer3D<> MyViewer; + KSpace K; + K.init( p1, p2, true ); + //! [viewer3D-extension-set-extension] + MyViewer viewer( K ); + viewer.setExtension( new RandomPointKeyExtension ); + //! [viewer3D-extension-set-extension] + viewer.show(); + viewer << domain; + viewer << p1 << p2 << p3; + + viewer << MyViewer::updateDisplay; + return application.exec(); } // // /////////////////////////////////////////////////////////////////////////////// diff --git a/src/DGtal/io/Display3D.h b/src/DGtal/io/Display3D.h index d09cef774d..3ffe24e198 100644 --- a/src/DGtal/io/Display3D.h +++ b/src/DGtal/io/Display3D.h @@ -897,7 +897,7 @@ namespace DGtal std::set mySelectCallBackFcts; bool myBoundingPtChangedTag = false; - + //----end of protected datas // ------------------------- Internals ------------------------------------ diff --git a/src/DGtal/io/Display3D.ih b/src/DGtal/io/Display3D.ih index d2c183f41e..dc8bfdc279 100644 --- a/src/DGtal/io/Display3D.ih +++ b/src/DGtal/io/Display3D.ih @@ -1195,38 +1195,38 @@ DGtal::Display3D< Space ,KSpace >::updateBoundingBox(const RealPoint &p) } else { - if(p[0] myBoundingPtUp[0]) - { - myBoundingPtUp[0]= p[0]; - myBoundingPtChangedTag = true; - } - if(p[1] >myBoundingPtUp[1]) - { - myBoundingPtUp[1]= p[1]; - myBoundingPtChangedTag = true; - } - if(p[2] >myBoundingPtUp[2]) - { - myBoundingPtUp[2]= p[2]; - myBoundingPtChangedTag = true; - } + if ( p[ 0 ] < myBoundingPtLow[ 0 ] ) + { + myBoundingPtLow[ 0 ] = p[ 0 ]; + myBoundingPtChangedTag = true; + } + if ( p[ 1 ] < myBoundingPtLow[ 1 ] ) + { + myBoundingPtLow[ 1 ] = p[ 1 ]; + myBoundingPtChangedTag = true; + } + + if ( p[ 2 ] < myBoundingPtLow[ 2 ] ) + { + myBoundingPtLow[ 2 ] = p[ 2 ]; + myBoundingPtChangedTag = true; + } + + if ( p[ 0 ] > myBoundingPtUp[ 0 ] ) + { + myBoundingPtUp[ 0 ] = p[ 0 ]; + myBoundingPtChangedTag = true; + } + if ( p[ 1 ] > myBoundingPtUp[ 1 ] ) + { + myBoundingPtUp[ 1 ] = p[ 1 ]; + myBoundingPtChangedTag = true; + } + if ( p[ 2 ] > myBoundingPtUp[ 2 ] ) + { + myBoundingPtUp[ 2 ] = p[ 2 ]; + myBoundingPtChangedTag = true; + } } } diff --git a/src/DGtal/io/readers/GenericReader.h b/src/DGtal/io/readers/GenericReader.h index bf60df2fbf..d0d942e7d5 100644 --- a/src/DGtal/io/readers/GenericReader.h +++ b/src/DGtal/io/readers/GenericReader.h @@ -115,7 +115,6 @@ namespace DGtal static TContainer import(const std::string &filename, std::vector dimSpace= std::vector () ) throw(DGtal::IOException); - /** * Import a volume nd image file by specifying a value functor. * @@ -128,37 +127,42 @@ namespace DGtal * into the given image type (TContainer::Value). * **/ - template - static TContainer importWithValueFunctor(const std::string &filename, - const TFunctor &aFunctor, - std::vector dimSpace= std::vector ()) throw( DGtal::IOException ) + template + static TContainer importWithValueFunctor( + const std::string & filename, const TFunctor & aFunctor, + std::vector dimSpace = + std::vector() ) throw( DGtal::IOException ) { - BOOST_CONCEPT_ASSERT(( concepts::CUnaryFunctor )) ; + BOOST_CONCEPT_ASSERT( + (concepts::CUnaryFunctor)); DGtal::IOException dgtalio; - const std::string extension = filename.substr( filename.find_last_of(".") + 1 ); + const std::string extension = + filename.substr( filename.find_last_of( "." ) + 1 ); - if ( extension == "raw" ) - { - for ( unsigned int i = 0; i < dimSpace.size(); i++) - ASSERT( dimSpace[i] != 0 ); - typename TContainer::Point const pt; - for ( unsigned int i = 0; i < dimSpace.size(); i++) - pt[i] = dimSpace[i]; - - return RawReader< TContainer, TFunctor >::template importRaw( filename, pt, aFunctor ); - } - - trace.error() << "Extension " << extension<< " not yet implemented in DGtal GenericReader." << std::endl; - throw dgtalio; + if ( extension == "raw" ) + { + for ( unsigned int i = 0; i < dimSpace.size(); i++ ) + ASSERT( dimSpace[ i ] != 0 ); + typename TContainer::Point const pt; + for ( unsigned int i = 0; i < dimSpace.size(); i++ ) + pt[ i ] = dimSpace[ i ]; + + return RawReader::template importRaw( + filename, pt, aFunctor ); + } + + trace.error() << "Extension " << extension + << " not yet implemented in DGtal GenericReader." + << std::endl; + throw dgtalio; } - /** * Import a volume nd image file by specifying a value functor. * * @tparam TFunctor The type of the functor (should verify the * concept CUnaryFunctor ) - + * @param dimSpace a vector containing the n dimensional image * size. * @param filename the image filename to be imported. @@ -167,35 +171,38 @@ namespace DGtal * TContainer::Value, DGtal::Color >). * **/ - - template - static TContainer importWithColorFunctor(const std::string &filename, - const TFunctor &aFunctor, - std::vector dimSpace= std::vector ()) throw( DGtal::IOException ) + + template + static TContainer importWithColorFunctor( + const std::string & filename, const TFunctor & aFunctor, + std::vector dimSpace = + std::vector() ) throw( DGtal::IOException ) { - BOOST_CONCEPT_ASSERT(( concepts::CUnaryFunctor )) ; - + BOOST_CONCEPT_ASSERT( + (concepts::CUnaryFunctor)); + DGtal::IOException dgtalio; - const std::string extension = filename.substr( filename.find_last_of(".") + 1 ); + const std::string extension = + filename.substr( filename.find_last_of( "." ) + 1 ); - if ( extension == "raw" ) - { - for ( unsigned int i = 0; i < dimSpace.size(); i++) - ASSERT( dimSpace[i] != 0 ); - typename TContainer::Point const pt; - for ( unsigned int i = 0; i < dimSpace.size(); i++) - pt[i] = dimSpace[i]; - return RawReader< TContainer, TFunctor >::template importRaw( filename, pt, aFunctor); - } - - trace.error() << "Extension " << extension<< " not yet implemented in DGtal GenericReader." << std::endl; - throw dgtalio; + if ( extension == "raw" ) + { + for ( unsigned int i = 0; i < dimSpace.size(); i++ ) + ASSERT( dimSpace[ i ] != 0 ); + typename TContainer::Point const pt; + for ( unsigned int i = 0; i < dimSpace.size(); i++ ) + pt[ i ] = dimSpace[ i ]; + return RawReader::template importRaw< + DGtal::Color>( filename, pt, aFunctor ); } - - - + trace.error() << "Extension " << extension + << " not yet implemented in DGtal GenericReader." + << std::endl; + throw dgtalio; + } }; @@ -275,9 +282,11 @@ namespace DGtal { return DicomReader::importDicom(filename, aFunctor); } - else if (extension=="nii" || extension == "mha" || extension == "mhd" || extension =="tiff" || extension =="tif") + else if ( extension == "nii" || extension == "mha" || + extension == "mhd" || extension == "tiff" || + extension == "tif" ) { - return ITKReader::importITK(filename, aFunctor); + return ITKReader::importITK( filename, aFunctor ); } #endif @@ -353,7 +362,7 @@ namespace DGtal } else if ( extension == "mha" || extension == "mhd" ) { - return ITKReader::importITK(filename, aFunctor); + return ITKReader::importITK( filename, aFunctor ); } #endif diff --git a/src/DGtal/io/readers/GenericReader.ih b/src/DGtal/io/readers/GenericReader.ih index 1c5462c68a..1130ea5273 100644 --- a/src/DGtal/io/readers/GenericReader.ih +++ b/src/DGtal/io/readers/GenericReader.ih @@ -83,18 +83,20 @@ import( const std::string & filename, { return LongvolReader::importLongvol( filename ); } - else if ( extension == "pgm3d" || extension == "pgm3D" || extension == "p3d" || extension == "pgm" ) + else if ( extension == "pgm3d" || extension == "pgm3D" || + extension == "p3d" || extension == "pgm" ) { return PGMReader::importPGM3D( filename ); } #ifdef WITH_ITK - else if (extension=="nii" || extension == "mha" || extension == "mhd" || extension =="tiff" || extension =="tif") + else if ( extension == "nii" || extension == "mha" || extension == "mhd" || + extension == "tiff" || extension == "tif" ) { - return ITKReader::importITK(filename); + return ITKReader::importITK( filename ); } #endif - else if ( extension == "raw" ) + else if ( extension == "raw" ) { ASSERT( x != 0 && y != 0 && z != 0 ); typename TContainer::Point const pt(x, y, z); diff --git a/src/DGtal/io/readers/ITKReader.h b/src/DGtal/io/readers/ITKReader.h index 388a7d6b09..f5afe252f3 100644 --- a/src/DGtal/io/readers/ITKReader.h +++ b/src/DGtal/io/readers/ITKReader.h @@ -19,7 +19,8 @@ /** * @file ITKReader.h * @author Pierre Gueth (\c pierre.gueth@gmail.com ) - * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France + * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, + * UMR 5205), CNRS, France * * @author Bertrand Kerautret (\c bertrand.kerautret@loria.fr ) * LORIA (CNRS, UMR 7503), University of Lorraine, France @@ -59,49 +60,51 @@ namespace DGtal * @see ITKWriter * @see ITKIOTrait */ - template + template struct ITKReader { typedef TImage Image; typedef typename TImage::Value Value; typedef typename ITKIOTrait::ValueOut ValueOut; - BOOST_CONCEPT_ASSERT(( concepts::CImage )); BOOST_STATIC_ASSERT(( (TImage::Domain::dimension == 3) || (TImage::Domain::dimension == 2) )); - /** + /** * Import an Image with a format supported by ITK. * * First an ImageContainerByITKImage is constructed by using the * source type of the input ITK image, and in a second step the * resulting image type is adapted to the TImage type with the use * of the given Functor. - * + * * @param filename name of the input file. * @param aFunctor functor used to cast image values. * @tparam TFunctor the type of functor used in the export. * * @return read image */ - template::DefaultReadFunctor > - static Image importITK(const std::string & filename, - const TFunctor & aFunctor = TFunctor()) throw(DGtal::IOException); + template ::DefaultReadFunctor> + static Image importITK( + const std::string & filename, + const TFunctor & aFunctor = TFunctor() ) throw( DGtal::IOException ); - /** - * Get the type of the ITK image. + /** + * Get the type of the ITK image. * * @param filename name of the input file. * @return the ITK image component type. * **/ - static itk::ImageIOBase::IOComponentType getITKComponentType(const std::string & filename); + static itk::ImageIOBase::IOComponentType + getITKComponentType( const std::string & filename ); - private: + private: /** - * Read an DGtal image of type TypeDGtalImage with a format supported by ITK. - * (used by importITK) - * + * Read an DGtal image of type TypeDGtalImage with a format supported by + * ITK. (used by importITK) + * * @param filename name of the input file * @param aFunctor functor used to cast image values * @tparam TFunctor the type of functor used in the export. @@ -109,10 +112,9 @@ namespace DGtal * @return read image */ template - static Image readDGtalImageFromITKtypes(const std::string &filename, const TFunctor &aFunctor) throw(DGtal::IOException); - - - + static Image readDGtalImageFromITKtypes( + const std::string & filename, + const TFunctor & aFunctor ) throw( DGtal::IOException ); }; }//namespace diff --git a/src/DGtal/io/readers/ITKReader.ih b/src/DGtal/io/readers/ITKReader.ih index 21dccf2c19..63e3ea63ac 100644 --- a/src/DGtal/io/readers/ITKReader.ih +++ b/src/DGtal/io/readers/ITKReader.ih @@ -17,7 +17,8 @@ /** * @file * @author Pierre Gueth (\c pierre.gueth@gmail.com ) - * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France + * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, + * UMR 5205), CNRS, France * * * @author Bertrand Kerautret (\c bertrand.kerautret@loria.fr ) @@ -50,139 +51,141 @@ namespace DGtal { - template - template - I - ITKReader::importITK(const std::string& filename, const TFunctor& aFunctor) - throw(DGtal::IOException) + template + template + I ITKReader::importITK( + const std::string & filename, + const TFunctor & aFunctor ) throw( DGtal::IOException ) { typedef typename Image::Domain Domain; typedef typename Domain::Point Point; typedef itk::ImageIOBase::IOComponentType IOComponentType; - BOOST_CONCEPT_ASSERT(( concepts::CUnaryFunctor )) ; - const IOComponentType componentType = getITKComponentType(filename); + BOOST_CONCEPT_ASSERT( (concepts::CUnaryFunctor)); + const IOComponentType componentType = getITKComponentType( filename ); typedef unsigned char ElementType; - switch( componentType ) - { - - default: - case itk::ImageIOBase::UNKNOWNCOMPONENTTYPE: - std::cerr << "Unknown and unsupported component type!" << std::endl; - case itk::ImageIOBase::UCHAR: - { - typedef ImageContainerByITKImage DGtalITKImage; - Domain d; - DGtalITKImage im(d); - return readDGtalImageFromITKtypes(filename, aFunctor); - } - case itk::ImageIOBase::CHAR: - { - typedef ImageContainerByITKImage DGtalITKImage; - Domain d; - DGtalITKImage im(d); - return readDGtalImageFromITKtypes(filename, aFunctor); - } - case itk::ImageIOBase::USHORT: - { - typedef ImageContainerByITKImage DGtalITKImage; - Domain d; - DGtalITKImage im(d); - return readDGtalImageFromITKtypes(filename, aFunctor); - } - case itk::ImageIOBase::SHORT: - { - typedef ImageContainerByITKImage DGtalITKImage; - Domain d; - DGtalITKImage im(d); - return readDGtalImageFromITKtypes(filename, aFunctor); - } - case itk::ImageIOBase::ULONG: - { - typedef ImageContainerByITKImage DGtalITKImage; - Domain d; - DGtalITKImage im(d); - return readDGtalImageFromITKtypes(filename, aFunctor); - } - case itk::ImageIOBase::LONG: - { - typedef ImageContainerByITKImage DGtalITKImage; - Domain d; - DGtalITKImage im(d); - return readDGtalImageFromITKtypes(filename, aFunctor); - } - case itk::ImageIOBase::FLOAT: - { - typedef ImageContainerByITKImage DGtalITKImage; - Domain d; - DGtalITKImage im(d); - return readDGtalImageFromITKtypes(filename, aFunctor); - } - case itk::ImageIOBase::DOUBLE: - { - typedef ImageContainerByITKImage DGtalITKImage; - Domain d; - DGtalITKImage im(d); - return readDGtalImageFromITKtypes(filename, aFunctor); - } - } - + switch ( componentType ) + { + + default: + case itk::ImageIOBase::UNKNOWNCOMPONENTTYPE: + std::cerr << "Unknown and unsupported component type!" << std::endl; + case itk::ImageIOBase::UCHAR: + { + typedef ImageContainerByITKImage DGtalITKImage; + Domain d; + DGtalITKImage im( d ); + return readDGtalImageFromITKtypes( filename, aFunctor ); + } + case itk::ImageIOBase::CHAR: + { + typedef ImageContainerByITKImage DGtalITKImage; + Domain d; + DGtalITKImage im( d ); + return readDGtalImageFromITKtypes( filename, aFunctor ); + } + case itk::ImageIOBase::USHORT: + { + typedef ImageContainerByITKImage DGtalITKImage; + Domain d; + DGtalITKImage im( d ); + return readDGtalImageFromITKtypes( filename, aFunctor ); + } + case itk::ImageIOBase::SHORT: + { + typedef ImageContainerByITKImage DGtalITKImage; + Domain d; + DGtalITKImage im( d ); + return readDGtalImageFromITKtypes( filename, aFunctor ); + } + case itk::ImageIOBase::ULONG: + { + typedef ImageContainerByITKImage DGtalITKImage; + Domain d; + DGtalITKImage im( d ); + return readDGtalImageFromITKtypes( filename, aFunctor ); + } + case itk::ImageIOBase::LONG: + { + typedef ImageContainerByITKImage DGtalITKImage; + Domain d; + DGtalITKImage im( d ); + return readDGtalImageFromITKtypes( filename, aFunctor ); + } + case itk::ImageIOBase::FLOAT: + { + typedef ImageContainerByITKImage DGtalITKImage; + Domain d; + DGtalITKImage im( d ); + return readDGtalImageFromITKtypes( filename, aFunctor ); + } + case itk::ImageIOBase::DOUBLE: + { + typedef ImageContainerByITKImage DGtalITKImage; + Domain d; + DGtalITKImage im( d ); + return readDGtalImageFromITKtypes( filename, aFunctor ); + } + } } - template - itk::ImageIOBase::IOComponentType ITKReader::getITKComponentType(const std::string & filename) + template + itk::ImageIOBase::IOComponentType + ITKReader::getITKComponentType( const std::string & filename ) { typedef itk::ImageIOBase::IOComponentType IOComponentType; IOComponentType componentType; try - { - itk::ImageIOBase::Pointer imageIO = - itk::ImageIOFactory::CreateImageIO(filename.c_str(), - itk::ImageIOFactory::ReadMode ); - imageIO->SetFileName( filename.c_str() ); - imageIO->ReadImageInformation(); - componentType = imageIO->GetComponentType(); - } catch (itk::ExceptionObject &e) - { - trace.error() << e; - throw IOException(); - } + { + itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO( + filename.c_str(), itk::ImageIOFactory::ReadMode ); + imageIO->SetFileName( filename.c_str() ); + imageIO->ReadImageInformation(); + componentType = imageIO->GetComponentType(); + } + catch ( itk::ExceptionObject & e ) + { + trace.error() << e; + throw IOException(); + } return componentType; } - - - template + template template - typename ITKReader::Image ITKReader::readDGtalImageFromITKtypes(const std::string &filename, const TFunctor &aFunctor) - throw(DGtal::IOException) + typename ITKReader::Image ITKReader::readDGtalImageFromITKtypes( + const std::string & filename, + const TFunctor & aFunctor ) throw( DGtal::IOException ) { - + typedef typename TypeDGtalImage::ITKImagePointer ITKImagePointer; typedef typename Image::Domain Domain; ITKImagePointer itk_image = TypeDGtalImage::ITKImage::New(); try - { - typedef itk::ImageFileReader ITKImageReader; - typename ITKImageReader::Pointer reader = ITKImageReader::New(); + { + typedef itk::ImageFileReader + ITKImageReader; + typename ITKImageReader::Pointer reader = ITKImageReader::New(); - reader->SetFileName(filename); - reader->Update(); - reader->GetOutput(); + reader->SetFileName( filename ); + reader->Update(); + reader->GetOutput(); - itk_image = reader->GetOutput(); - } + itk_image = reader->GetOutput(); + } catch (itk::ExceptionObject &e) - { - trace.error() << e; - throw IOException(); - } + { + trace.error() << e; + throw IOException(); + } - const TypeDGtalImage dgtal_itk_image(itk_image); + const TypeDGtalImage dgtal_itk_image( itk_image ); const Domain& domain = dgtal_itk_image.domain(); - typedef ConstImageAdapter AdaptedImage; + typedef ConstImageAdapter + AdaptedImage; const functors::Identity identityFunctor{}; const AdaptedImage adapted(dgtal_itk_image, domain, identityFunctor, aFunctor); @@ -191,5 +194,4 @@ namespace DGtal { return image; } - }//namespace diff --git a/src/DGtal/io/readers/PGMReader.h b/src/DGtal/io/readers/PGMReader.h index de21935466..823b3d6807 100644 --- a/src/DGtal/io/readers/PGMReader.h +++ b/src/DGtal/io/readers/PGMReader.h @@ -58,14 +58,14 @@ namespace DGtal /** * Description of class 'PGMReader'

* \brief Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode). - * - PPM: RGB + * - PPM: RGB * - PGM: grayscale * - PPM3D: 3D variant of PPM * - PGM3D: 3D variant of PGM - * + * * * Simple example: (extract from test file testPGMReader.cpp) - * + * * @code * #include "DGtal/helpers/StdDefs.h" * #include "DGtal/io/readers/PGMReader.h" @@ -73,29 +73,30 @@ namespace DGtal * ... * string filename = "test.pgm"; * typedef ImageSelector < Z2i::Domain, uint>::Type Image; - * Image image = PGMReader::importPGM( filename ); + * Image image = PGMReader::importPGM( filename ); * @endcode * You can then for instance display a threshold part of the image: - * @code - * #include "DGtal/kernel/imagesSetsUtils/SetFromImage.h" + * @code + * #include "DGtal/kernel/imagesSetsUtils/SetFromImage.h" * ... * Z2i::DigitalSet set2d (image.domain()); - * // Threshold all pixel in ]0, 255] in a DigitalSet + * // Threshold all pixel in ]0, 255] in a DigitalSet * SetFromImage::append(set2d, image, 0, 255); * Board2D board; - * board << image.domain() << set2d; // display domain and set + * board << image.domain() << set2d; // display domain and set * @endcode * * @tparam TImageContainer the type of the image container * - * @tparam TFunctor the type of functor used in the import (by default set to functors::Cast< TImageContainer::Value>) . + * @tparam TFunctor the type of functor used in the import (by default set to + * functors::Cast< TImageContainer::Value>) . * */ - template > - struct PGMReader - { - // ----------------------- Standard services ------------------------------ +template > +struct PGMReader +{ + // ----------------------- Standard services ------------------------------ public: typedef TImageContainer ImageContainer; diff --git a/src/DGtal/io/readers/TableReader.h b/src/DGtal/io/readers/TableReader.h index 0ce0fc0344..8aa0801594 100644 --- a/src/DGtal/io/readers/TableReader.h +++ b/src/DGtal/io/readers/TableReader.h @@ -53,7 +53,8 @@ namespace DGtal // class TableReader /** * Description of class 'TableReader'

- * \brief Aim: Implements method to read a set of numbers represented in each line of a file. + * \brief Aim: Implements method to read a set of numbers represented in each + *line of a file. * * * The main method to read a set of numbers where each number is @@ -68,11 +69,13 @@ namespace DGtal * #include "DGtal/io/readers/TableReader.h" * .... * string filename= "testFile.dat"; - * vector vectPoints = TableReader::getColumnElementsFromFile(filename); + * vector vectPoints = TableReader::getColumnElementsFromFile(filename); * @endcode * and you can specifying the point position: * @code - * vector vectPoints = TableReader::getColumnElementsFromFile(filename, 2); + * vector vectPoints = TableReader::getColumnElementsFromFile(filename, 2); * @endcode * * @see testTableReader.cpp @@ -84,65 +87,62 @@ namespace DGtal { // ----------------------- Standard services ------------------------------ public: + /** + * Method to import a vector containing a list of elements given + * in an input stream. One element is extracted on each line of + * the input stream. Each elements are identified between space + * or tab characters. Blank line or line beginning with "#" are + * skipped. + * + * @param aFilename a file name + * @param aPosition the position of indices where the element has to be + *extracted. + * @return a vector containing the set of elements. + **/ + static std::vector + getColumnElementsFromFile( const std::string & aFilename, + unsigned int aPosition ); + + /** + * Method to import a vector containing a list of elements given + * in a file. One element is extracted on each line of the input + * file. Each elements are identified between space or tab + * characters. Blank line or line beginning with "#" are skipped. + * + * @param in the input file. + * @param aPosition the position of indices where the elements has to be + *extracted. + * @return a vector containing the set of elements. + **/ + + static std::vector + getColumnElementsFromInputStream( std::istream & in, unsigned int aPosition ); + + /** + * Method to import a vector where each element contains the line + * elements of a given file. Each elements are identified between + * space or tab characters. Blank line or line beginning with "#" + * are skipped. + * + * @param aFilename the input file. + * @return a vector containing a vector which contains each line elements. + **/ + static std::vector> + getLinesElementsFromFile( const std::string & aFilename ); + + /** + * Method to import a vector where each element contains the line + * elements of a given file. Each elements are identified between + * space or tab characters. Blank line or line beginning with "#" + * are skipped. + * + * @param in the input file. + * @return a vector containing a vector which contains each line elements. + **/ + static std::vector> + getLinesElementsFromInputStream( std::istream & in ); - /** - * Method to import a vector containing a list of elements given - * in an input stream. One element is extracted on each line of - * the input stream. Each elements are identified between space - * or tab characters. Blank line or line beginning with "#" are - * skipped. - * - * @param aFilename a file name - * @param aPosition the position of indices where the element has to be extracted. - * @return a vector containing the set of elements. - **/ - static std::vector< TQuantity > - getColumnElementsFromFile (const std::string & aFilename, - unsigned int aPosition); - - /** - * Method to import a vector containing a list of elements given - * in a file. One element is extracted on each line of the input - * file. Each elements are identified between space or tab - * characters. Blank line or line beginning with "#" are skipped. - * - * @param in the input file. - * @param aPosition the position of indices where the elements has to be extracted. - * @return a vector containing the set of elements. - **/ - - static std::vector< TQuantity > - getColumnElementsFromInputStream (std::istream &in, - unsigned int aPosition); - - /** - * Method to import a vector where each element contains the line - * elements of a given file. Each elements are identified between - * space or tab characters. Blank line or line beginning with "#" - * are skipped. - * - * @param aFilename the input file. - * @return a vector containing a vector which contains each line elements. - **/ - static std::vector > - getLinesElementsFromFile (const std::string & aFilename); - - /** - * Method to import a vector where each element contains the line - * elements of a given file. Each elements are identified between - * space or tab characters. Blank line or line beginning with "#" - * are skipped. - * - * @param in the input file. - * @return a vector containing a vector which contains each line elements. - **/ - - static std::vector > - getLinesElementsFromInputStream (std::istream &in); - - - }; // end of class TableReader diff --git a/src/DGtal/io/readers/TableReader.ih b/src/DGtal/io/readers/TableReader.ih index beb68ba270..99eff68a22 100644 --- a/src/DGtal/io/readers/TableReader.ih +++ b/src/DGtal/io/readers/TableReader.ih @@ -54,94 +54,85 @@ DGtal::TableReader::getColumnElementsFromFile (const std::string &aFi return TableReader::getColumnElementsFromInputStream(infile, aPosition); } - -template -inline -std::vector< TQuantity > -DGtal::TableReader::getColumnElementsFromInputStream (std::istream &in, - unsigned int aPosition) +template +inline std::vector +DGtal::TableReader::getColumnElementsFromInputStream( +std::istream & in, unsigned int aPosition ) { std::vector vectResult; std::string str; getline(in, str ); while ( in.good() ) + { + if ( ( str != "" ) && ( str[ 0 ] != '#' ) ) { - if ( ( str != "" ) && ( str[ 0 ] != '#' ) ) + std::istringstream in_str( str ); + std::string wordVal; + TQuantity val; + bool found = false; + unsigned int idx = 0; + while ( in_str.good() && !found ) + { + std::operator>>( in_str, wordVal ); + std::istringstream word_str( wordVal ); + word_str >> val; + bool isOK = !word_str.fail(); + if ( isOK && idx == aPosition ) { - std::istringstream in_str( str ); - std::string wordVal; - TQuantity val; - bool found = false; - unsigned int idx = 0; - while ( in_str.good()&& !found) - { - std::operator>>(in_str, wordVal); - std::istringstream word_str( wordVal ); - word_str >> val; - bool isOK = !word_str.fail(); - if (isOK && idx == aPosition) - { - found=true; - vectResult.push_back(val); - } - idx++; - } - } - getline(in, str ); + found = true; + vectResult.push_back( val ); + } + idx++; + } } + getline( in, str ); + } return vectResult; } - -template -inline -std::vector > -DGtal::TableReader::getLinesElementsFromFile (const std::string & aFilename) +template +inline std::vector> +DGtal::TableReader::getLinesElementsFromFile( +const std::string & aFilename ) { std::ifstream infile; - infile.open (aFilename.c_str(), std::ifstream::in); - return DGtal::TableReader::getLinesElementsFromInputStream(infile); - + infile.open( aFilename.c_str(), std::ifstream::in ); + return DGtal::TableReader::getLinesElementsFromInputStream( + infile ); } - - -template -inline -std::vector > -DGtal::TableReader::getLinesElementsFromInputStream (std::istream &in) +template +inline std::vector> +DGtal::TableReader::getLinesElementsFromInputStream( +std::istream & in ) { - std::vector < std::vector > vectResult; + std::vector> vectResult; std::string str; - getline(in, str ); + getline( in, str ); while ( in.good() ) + { + std::vector aLine; + if ( ( str != "" ) && ( str[ 0 ] != '#' ) ) { - std::vector aLine; - if ( ( str != "" ) && ( str[ 0 ] != '#' ) ) + std::istringstream in_str( str ); + std::string wordVal; + TQuantity val; + while ( in_str.good() ) + { + std::operator>>( in_str, wordVal ); + std::istringstream word_str( wordVal ); + word_str >> val; + if ( !word_str.fail() ) { - std::istringstream in_str( str ); - std::string wordVal; - TQuantity val; - while ( in_str.good()) - { - std::operator>>(in_str, wordVal); - std::istringstream word_str( wordVal ); - word_str >> val; - if (!word_str.fail()) - { - aLine.push_back(val); - } - } - vectResult.push_back(aLine); + aLine.push_back( val ); } - getline(in, str ); + } + vectResult.push_back( aLine ); } + getline( in, str ); + } return vectResult; - } - - - // // /////////////////////////////////////////////////////////////////////////////// diff --git a/src/DGtal/io/viewers/Viewer3D.h b/src/DGtal/io/viewers/Viewer3D.h index 8792a163ad..e65bb56dc5 100644 --- a/src/DGtal/io/viewers/Viewer3D.h +++ b/src/DGtal/io/viewers/Viewer3D.h @@ -127,173 +127,180 @@ namespace DGtal * * @see Display3D, Board3DTo2D */ - template < typename TSpace = SpaceND<3>, - typename TKSpace = KhalimskySpaceND<3> > + template , + typename TKSpace = KhalimskySpaceND<3>> class Viewer3D : public QGLViewer, public Display3D { - BOOST_CONCEPT_ASSERT((concepts::CSpace)); + BOOST_CONCEPT_ASSERT( (concepts::CSpace)); //---------------overwritting some functions of Display3D ------------------- // ----------------------- public types ------------------------------ public: - typedef TSpace Space; - typedef TKSpace KSpace; - typedef Viewer3D Self; - typedef Display3D Display; - typedef typename Display::SelectCallbackFct SelectCallbackFct; - typedef typename Display::RealPoint RealPoint; - using Display::getSelectCallback3D; + typedef TSpace Space; + typedef TKSpace KSpace; + typedef Viewer3D Self; + typedef Display3D Display; + typedef typename Display::SelectCallbackFct SelectCallbackFct; + typedef typename Display::RealPoint RealPoint; + using Display::getSelectCallback3D; + + enum RenderingMode + { + RenderingDefault, + RenderingMetallic, + RenderingPlastic, + RenderingLambertian + }; - enum RenderingMode {RenderingDefault, RenderingMetallic, RenderingPlastic, RenderingLambertian }; + /** + * Interface that can be used so that one can extend a few service + * of Viewer3D, like keyPressEvent and others. You may thus give an + * extension to a Viewer3D by simply handling it a pointer to an + * object deriving from this class. + */ + struct Extension + { + /// The associated viewer. + typedef Viewer3D Viewer; + + /// This method may be overloaded to capture other key + /// events. It will be called at the beginning of Viewer3D::keyPressEvent. + /// + /// @param viewer the viewer calling this method + /// @param event the key event + /// + /// @return 'true' if the event was handled (in this case, + /// Viewer3D::keyPressEvent will not do anything). + virtual bool keyPressEvent( Viewer & viewer, QKeyEvent * event ) + { + boost::ignore_unused_variable_warning( viewer ); + boost::ignore_unused_variable_warning( event ); + return false; + } - /** - * Interface that can be used so that one can extend a few service - * of Viewer3D, like keyPressEvent and others. You may thus give an - * extension to a Viewer3D by simply handling it a pointer to an - * object deriving from this class. - */ - struct Extension { - /// The associated viewer. - typedef Viewer3D Viewer; - - /// This method may be overloaded to capture other key - /// events. It will be called at the beginning of Viewer3D::keyPressEvent. - /// - /// @param viewer the viewer calling this method - /// @param event the key event - /// - /// @return 'true' if the event was handled (in this case, - /// Viewer3D::keyPressEvent will not do anything). - virtual bool keyPressEvent ( Viewer& viewer, QKeyEvent * event ) - { - boost::ignore_unused_variable_warning( viewer ); - boost::ignore_unused_variable_warning( event ); - return false; - } + /// This method may be overloaded and is called at the beginning + /// of Viewer3D::drawWithNames. This method is useful for + /// drawing elements with additional information for selection. + /// + /// @param viewer the viewer calling this method + virtual void drawWithNames( Viewer & viewer ) + { + boost::ignore_unused_variable_warning( viewer ); + } - /// This method may be overloaded and is called at the beginning - /// of Viewer3D::drawWithNames. This method is useful for - /// drawing elements with additional information for selection. - /// - /// @param viewer the viewer calling this method - virtual void drawWithNames( Viewer& viewer ) - { - boost::ignore_unused_variable_warning( viewer ); - } - - /// This method may be overloaded and is called at the beginning - /// of Viewer3D::draw. This method is called for drawing - /// elements. - /// - /// @param viewer the viewer calling this method - virtual void draw( Viewer& viewer ) - { - boost::ignore_unused_variable_warning( viewer ); - } - - /// This method may be overloaded and is called at QGLViewer - /// initialization. It will be called at the beginning of - /// Viewer3D::init. - /// @param viewer the viewer calling this method - virtual void init(Viewer& viewer) - { - boost::ignore_unused_variable_warning( viewer ); - } + /// This method may be overloaded and is called at the beginning + /// of Viewer3D::draw. This method is called for drawing + /// elements. + /// + /// @param viewer the viewer calling this method + virtual void draw( Viewer & viewer ) + { + boost::ignore_unused_variable_warning( viewer ); + } - /// This method may be overloaded and is called when pressing - /// help. It will be added before Viewer3D::helpString. - /// - /// @param viewer the viewer calling this method - /// @return astring corresponding to the help of the viewer (list of commands, etc) - virtual QString helpString(const Viewer& viewer) const - { - boost::ignore_unused_variable_warning( viewer ); - return ""; - } + /// This method may be overloaded and is called at QGLViewer + /// initialization. It will be called at the beginning of + /// Viewer3D::init. + /// @param viewer the viewer calling this method + virtual void init( Viewer & viewer ) + { + boost::ignore_unused_variable_warning( viewer ); + } - /// This method may be overloaded to take care of a mouse - /// selection event. It will be called at the beginning of - /// Viewer3D::postSelection. - /// - /// @param viewer the viewer calling this method - /// @param point the point clicked by the user in the window - /// - /// @return 'true' if the event was handled (in this case, - /// Viewer3D::postSelection will not do anything). - virtual bool postSelection(const Viewer& viewer, const QPoint& point ) - { - boost::ignore_unused_variable_warning( viewer ); - boost::ignore_unused_variable_warning( point ); - return false; - } + /// This method may be overloaded and is called when pressing + /// help. It will be added before Viewer3D::helpString. + /// + /// @param viewer the viewer calling this method + /// @return astring corresponding to the help of the viewer (list of + /// commands, etc) + virtual QString helpString( const Viewer & viewer ) const + { + boost::ignore_unused_variable_warning( viewer ); + return ""; + } - /// This method may be overloaded to capture other mouse move - /// events. It will be called at the beginning of Viewer3D::mouseMoveEvent. - /// - /// @param viewer the viewer calling this method - /// @param event the mouse move event - /// - /// @return 'true' if the event was handled (in this case, - /// Viewer3D::mouseMoveEvent will not do anything). - virtual bool mouseMoveEvent(const Viewer& viewer, QMouseEvent* event ) - { - boost::ignore_unused_variable_warning( viewer ); - boost::ignore_unused_variable_warning( event ); - return false; - } + /// This method may be overloaded to take care of a mouse + /// selection event. It will be called at the beginning of + /// Viewer3D::postSelection. + /// + /// @param viewer the viewer calling this method + /// @param point the point clicked by the user in the window + /// + /// @return 'true' if the event was handled (in this case, + /// Viewer3D::postSelection will not do anything). + virtual bool postSelection( const Viewer & viewer, const QPoint & point ) + { + boost::ignore_unused_variable_warning( viewer ); + boost::ignore_unused_variable_warning( point ); + return false; + } - /// This method may be overloaded to capture other mouse press - /// events. It will be called at the beginning of Viewer3D::mousePressEvent. - /// - /// @param viewer the viewer calling this method - /// @param event the mouse press event - /// - /// @return 'true' if the event was handled (in this case, - /// Viewer3D::mousePressEvent will not do anything). - virtual bool mousePressEvent(const Viewer& viewer, QMouseEvent* event ) - { - boost::ignore_unused_variable_warning( viewer ); - boost::ignore_unused_variable_warning( event ); - return false; - } + /// This method may be overloaded to capture other mouse move + /// events. It will be called at the beginning of Viewer3D::mouseMoveEvent. + /// + /// @param viewer the viewer calling this method + /// @param event the mouse move event + /// + /// @return 'true' if the event was handled (in this case, + /// Viewer3D::mouseMoveEvent will not do anything). + virtual bool mouseMoveEvent( const Viewer & viewer, QMouseEvent * event ) + { + boost::ignore_unused_variable_warning( viewer ); + boost::ignore_unused_variable_warning( event ); + return false; + } - /// This method may be overloaded to capture other mouse release - /// events. It will be called at the beginning of Viewer3D::mouseReleaseEvent. - /// - /// @param viewer the viewer calling this method - /// @param event the mouse release event - /// - /// @return 'true' if the event was handled (in this case, - /// Viewer3D::mouseReleaseEvent will not do anything). - virtual bool mouseReleaseEvent(const Viewer& viewer, QMouseEvent* event ) - { - boost::ignore_unused_variable_warning( viewer ); - boost::ignore_unused_variable_warning( event ); - return false; - } + /// This method may be overloaded to capture other mouse press + /// events. It will be called at the beginning of Viewer3D::mousePressEvent. + /// + /// @param viewer the viewer calling this method + /// @param event the mouse press event + /// + /// @return 'true' if the event was handled (in this case, + /// Viewer3D::mousePressEvent will not do anything). + virtual bool mousePressEvent( const Viewer & viewer, QMouseEvent * event ) + { + boost::ignore_unused_variable_warning( viewer ); + boost::ignore_unused_variable_warning( event ); + return false; + } - }; - - // ----------------------- Standard services ------------------------------ + /// This method may be overloaded to capture other mouse release + /// events. It will be called at the beginning of + /// Viewer3D::mouseReleaseEvent. + /// + /// @param viewer the viewer calling this method + /// @param event the mouse release event + /// + /// @return 'true' if the event was handled (in this case, + /// Viewer3D::mouseReleaseEvent will not do anything). + virtual bool mouseReleaseEvent( const Viewer & viewer, QMouseEvent * event ) + { + boost::ignore_unused_variable_warning( viewer ); + boost::ignore_unused_variable_warning( event ); + return false; + } + }; + + // ----------------------- Standard services ------------------------------ public: /** * Constructor */ - Viewer3D() :QGLViewer(), Display3D(), - myExtension( 0 ) - { - resize(800,600); + Viewer3D() : QGLViewer(), Display3D(), myExtension( 0 ) + { + resize( 800, 600 ); }; /** *Constructor with a khalimsky space * @param KSEmb the Khalimsky space */ - Viewer3D(const KSpace &KSEmb):QGLViewer(), Display3D(KSEmb), - myExtension( 0 ) + Viewer3D( const KSpace & KSEmb ) + : QGLViewer(), Display3D( KSEmb ), myExtension( 0 ) { resize(800,600); } @@ -301,9 +308,10 @@ namespace DGtal /// Sets the extension \a ext to the viewer. The object is /// acquired by the viewer and should be dynamically allocated. /// @param ext any dynamically allocated object deriving from Extension. - void setExtension( Extension* ext ) + void setExtension( Extension * ext ) { - if ( myExtension != 0 ) delete myExtension; + if ( myExtension != 0 ) + delete myExtension; myExtension = ext; } @@ -311,10 +319,11 @@ namespace DGtal /// no extension was present. void removeExtension() { - if ( myExtension != 0 ) delete myExtension; + if ( myExtension != 0 ) + delete myExtension; myExtension = 0; } - + /** * Set camera position. * @param ax x position. @@ -963,94 +972,93 @@ namespace DGtal public: + /// To call the protected method `drawLight`. + void drawSomeLight( GLenum light ) const + { + QGLViewer::drawLight( light ); + } + /// To call the protected method `drawLight`. + void drawSomeLight( GLenum light, float zoom ) const + { + QGLViewer::drawLight( light, zoom ); + } - /// To call the protected method `drawLight`. - void drawSomeLight( GLenum light ) const - { - QGLViewer::drawLight( light ); - } - /// To call the protected method `drawLight`. - void drawSomeLight( GLenum light, float zoom ) const - { - QGLViewer::drawLight( light, zoom ); - } - - - + // ------------------------- Hidden services ------------------------------ + // protected: - // ------------------------- Hidden services ------------------------------ - //protected: + /** + * Permit to update the OpenGL list to be displayed. + * Need to called after a number of addVoxel or after a + * sortSurfelFromCamera(). + * @param needToUpdateBoundingBox flag to update the bounding box + */ + void updateList( bool needToUpdateBoundingBox = true ); + /** + * Draw a ball by using quads strip primitive. + * @param[in] aBall the ball to be drawn + */ + void glDrawGLBall( const typename Viewer3D::BallD3D & aBall ); - /** - * Permit to update the OpenGL list to be displayed. - * Need to called after a number of addVoxel or after a sortSurfelFromCamera(). - * @param needToUpdateBoundingBox flag to update the bounding box - */ - void updateList ( bool needToUpdateBoundingBox=true ); + /** + * Used to manage new key event (wich are added from the default + * QGLviewer keys). + * + * Note that when a new key event is taken into account it could be + * added in the QGLviewer init() method to update automatically the + * key description in the help QGLviewer window. For instance when + * a new key is processed in this method you simply should add the following + * code in the init() method: + @code + setKeyDescription(Qt::Key_NEW, "Description of the new Key."); + @endcode - /** - * Draw a ball by using quads strip primitive. - * @param[in] aBall the ball to be drawn - */ - void glDrawGLBall (const typename Viewer3D::BallD3D & aBall ); - + * + * @param e the QKeyEvent + **/ + virtual void keyPressEvent( QKeyEvent * e ); + /** + * Used to manage a mouse move event (to handle light move). + * + * @param e the QMouseEvent + **/ + virtual void mouseMoveEvent( QMouseEvent * e ); - /** - * Used to manage new key event (wich are added from the default - * QGLviewer keys). - * - * Note that when a new key event is taken into account it could be - * added in the QGLviewer init() method to update automatically the - * key description in the help QGLviewer window. For instance when - * a new key is processed in this method you simply should add the following - * code in the init() method: + /** + * Used to manage a mouse press event (to handle light move). + * + * @param e the QMouseEvent + **/ + virtual void mousePressEvent( QMouseEvent * e ); - @code - setKeyDescription(Qt::Key_NEW, "Description of the new Key."); - @endcode + /** + * Used to manage a mouse release event (to handle light move). + * + * @param e the QMouseEvent + **/ + virtual void mouseReleaseEvent( QMouseEvent * e ); - * - * @param e the QKeyEvent - **/ - virtual void keyPressEvent ( QKeyEvent *e ); - - /** - * Used to manage a mouse move event (to handle light move). - * - * @param e the QMouseEvent - **/ - virtual void mouseMoveEvent ( QMouseEvent *e ); - - /** - * Used to manage a mouse press event (to handle light move). - * - * @param e the QMouseEvent - **/ - virtual void mousePressEvent ( QMouseEvent *e ); - - /** - * Used to manage a mouse release event (to handle light move). - * - * @param e the QMouseEvent - **/ - virtual void mouseReleaseEvent ( QMouseEvent *e ); - - /** - * Used to sort pixel from camera - **/ - struct CompFarthestVoxelFromCamera + /** + * Used to sort pixel from camera + **/ + struct CompFarthestVoxelFromCamera + { + qglviewer::Vec posCam; + bool operator()( typename Viewer3D::CubeD3D s1, + typename Viewer3D::CubeD3D s2 ) { - qglviewer::Vec posCam; - bool operator() (typename Viewer3D::CubeD3D s1, - typename Viewer3D::CubeD3D s2 ) - { - double dist1= sqrt ( ( posCam.x-s1.center[0] ) * ( posCam.x-s1.center[0] ) + ( posCam.y-s1.center[1] ) * ( posCam.y-s1.center[1] ) + ( posCam.z-s1.center[2] ) * ( posCam.z-s1.center[2] ) ); - double dist2= sqrt ( ( posCam.x-s2.center[0] ) * ( posCam.x-s2.center[0] ) + ( posCam.y-s2.center[1] ) * ( posCam.y-s2.center[1] ) + ( posCam.z-s2.center[2] ) * ( posCam.z-s2.center[2] ) ); - return dist1>dist2; - } + double dist1 = + sqrt( ( posCam.x - s1.center[ 0 ] ) * ( posCam.x - s1.center[ 0 ] ) + + ( posCam.y - s1.center[ 1 ] ) * ( posCam.y - s1.center[ 1 ] ) + + ( posCam.z - s1.center[ 2 ] ) * ( posCam.z - s1.center[ 2 ] ) ); + double dist2 = + sqrt( ( posCam.x - s2.center[ 0 ] ) * ( posCam.x - s2.center[ 0 ] ) + + ( posCam.y - s2.center[ 1 ] ) * ( posCam.y - s2.center[ 1 ] ) + + ( posCam.z - s2.center[ 2 ] ) * ( posCam.z - s2.center[ 2 ] ) ); + return dist1 > dist2; + } }; @@ -1650,21 +1658,19 @@ namespace DGtal /// Used to store all the domains std::vector myImageDomainList; /// Stored a possible extension to the viewer (pointer owned). - Extension* myExtension; - - }; // end of class Viewer3D - + Extension * myExtension; + }; // end of class Viewer3D - template < typename TSpace, typename TKSpace> + template /** * Overloads 'operator<<' for displaying objects of class 'Viewer3D'. * @param out the output stream where the object is written. * @param object the object of class 'Viewer3D' to write. * @return the output stream after the writing. */ - std::ostream& - operator<< ( std::ostream & out, const Viewer3D & object ); + std::ostream & operator<<( std::ostream & out, + const Viewer3D & object ); } // namespace DGtal diff --git a/src/DGtal/io/viewers/Viewer3D.ih b/src/DGtal/io/viewers/Viewer3D.ih index 0854054c32..b6d39904ed 100644 --- a/src/DGtal/io/viewers/Viewer3D.ih +++ b/src/DGtal/io/viewers/Viewer3D.ih @@ -62,35 +62,32 @@ using namespace qglviewer; /////////////////////////////////////////////////////////////////////////////// // Implementation of inline methods // - - -template < typename TSpace, typename TKSpace > -inline -void -DGtal::Viewer3D::rotateDomain(Image2DDomainD3D &anDom, double angleRotation, - ImageDirection rotationDir){ +template +inline void DGtal::Viewer3D::rotateDomain( +Image2DDomainD3D & anDom, double angleRotation, ImageDirection rotationDir ) +{ DGtal::PointVector<3, int> pt; pt[0] = (int) (anDom.point1[0]+anDom.point2[0]+anDom.point3[0]+anDom.point4[0])/4.0; 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::LineD3D> &aVectLine = Viewer3D::myLineSetList.at(anDom.myLineSetIndex); + + std::vector::LineD3D> & aVectLine = + Viewer3D::myLineSetList.at( anDom.myLineSetIndex ); for(unsigned int i = 0; i< aVectLine.size();i++){ - typename DGtal::Display3D::LineD3D &aLine = aVectLine.at(i); + typename DGtal::Display3D::LineD3D & aLine = + aVectLine.at( i ); rotateLineD3D(aLine, pt, angleRotation, rotationDir ); } } - -template < typename TSpace, typename TKSpace > +template template -inline -void -DGtal::Viewer3D::rotatePoint(TValues &x, TValues &y, TValues &z, - double cx, double cy, double cz, - double angleRotation, ImageDirection rotationDir){ +inline void DGtal::Viewer3D::rotatePoint( +TValues & x, TValues & y, TValues & z, double cx, double cy, double cz, +double angleRotation, ImageDirection rotationDir ) +{ double dx = x-cx; double dy = y-cy; double dz = z-cz; if(rotationDir == zDirection){ x = cx+dx*cos(angleRotation)-dy*sin(angleRotation); @@ -106,16 +103,13 @@ DGtal::Viewer3D::rotatePoint(TValues &x, TValues &y, TValues &z } } - - - -template < typename TSpace, typename TKSpace > -template < typename TContainer > -inline -void -DGtal::Viewer3D::rotateLineD3D(typename DGtal::Display3D::LineD3D &aLine, - DGtal::PointVector<3, int, TContainer> pt, - double angleRotation, ImageDirection dirRotation){ +template +template +inline void DGtal::Viewer3D::rotateLineD3D( +typename DGtal::Display3D::LineD3D & aLine, +DGtal::PointVector<3, int, TContainer> pt, double angleRotation, +ImageDirection dirRotation ) +{ double dx1 = aLine.point1[0] - pt[0]; double dy1 = aLine.point1[1] - pt[1]; double dz1 = aLine.point1[2] - pt[2]; double dx2 = aLine.point2[0] - pt[0]; double dy2 = aLine.point2[1] - pt[1]; double dz2 = aLine.point2[2] - pt[2]; if(dirRotation==zDirection){ @@ -143,49 +137,40 @@ DGtal::Viewer3D::rotateLineD3D(typename DGtal::Display3D -inline -unsigned int -DGtal::Viewer3D::getCurrentDomainNumber() +template +inline unsigned int DGtal::Viewer3D::getCurrentDomainNumber() { return myImageDomainList.size(); } -template < typename TSpace, typename TKSpace > -inline -unsigned int -DGtal::Viewer3D::getCurrentGLImageNumber() +template +inline unsigned int DGtal::Viewer3D::getCurrentGLImageNumber() { return myGSImageList.size(); } - -template < typename TSpace, typename TKSpace > -inline -void -DGtal::Viewer3D::addTextureImage(const typename Viewer3D::TextureImage &image) +template +inline void DGtal::Viewer3D::addTextureImage( +const typename Viewer3D::TextureImage & image ) { myGSImageList.push_back(image); - Display3D::updateBoundingBox(image.point1); - Display3D::updateBoundingBox(image.point2); - Display3D::updateBoundingBox(image.point3); - Display3D::updateBoundingBox(image.point4); + Display3D::updateBoundingBox( image.point1 ); + Display3D::updateBoundingBox( image.point2 ); + Display3D::updateBoundingBox( image.point3 ); + Display3D::updateBoundingBox( image.point4 ); } - - -template < typename TSpace, typename TKSpace > -template < typename TImageType, typename TFunctor > -inline -void -DGtal::Viewer3D::updateTextureImage(unsigned int imageIndex, const TImageType & image, const TFunctor & aFunctor, - double xTranslation, double yTranslation, double zTranslation, - double rotationAngle, ImageDirection rotationDir) +template +template +inline void DGtal::Viewer3D::updateTextureImage( +unsigned int imageIndex, const TImageType & image, const TFunctor & aFunctor, +double xTranslation, double yTranslation, double zTranslation, +double rotationAngle, ImageDirection rotationDir ) { BOOST_CONCEPT_ASSERT(( concepts::CConstImage < TImageType > )); assert ( imageIndex< myGSImageList.size()); - typename Viewer3D::TextureImage &anImage = myGSImageList.at(imageIndex); + typename Viewer3D::TextureImage & anImage = + myGSImageList.at( imageIndex ); Display::updateBoundingBox(RealPoint(anImage.point1[0]+xTranslation, anImage.point1[1]+yTranslation, anImage.point1[2]+zTranslation)); @@ -210,22 +195,18 @@ DGtal::Viewer3D::updateTextureImage(unsigned int imageIndex, co } } - -template < typename TSpace, typename TKSpace > -inline -void -DGtal::Viewer3D::updateOrientationTextureImage(unsigned int imageIndex, - double xPosition, - double yPosition, - double zPosition, - ImageDirection newDirection) +template +inline void DGtal::Viewer3D::updateOrientationTextureImage( +unsigned int imageIndex, double xPosition, double yPosition, double zPosition, +ImageDirection newDirection ) { assert ( imageIndex< myGSImageList.size()); - typename Viewer3D::TextureImage &anImage = myGSImageList.at(imageIndex); - Display3D::updateBoundingBox(anImage.point1); - Display3D::updateBoundingBox(anImage.point2); - Display3D::updateBoundingBox(anImage.point3); - Display3D::updateBoundingBox(anImage.point4); + typename Viewer3D::TextureImage & anImage = + myGSImageList.at( imageIndex ); + Display3D::updateBoundingBox( anImage.point1 ); + Display3D::updateBoundingBox( anImage.point2 ); + Display3D::updateBoundingBox( anImage.point3 ); + Display3D::updateBoundingBox( anImage.point4 ); anImage.updateImageOrientation(newDirection, xPosition, yPosition, zPosition); if(anImage.myDrawDomain) { @@ -236,30 +217,27 @@ DGtal::Viewer3D::updateOrientationTextureImage(unsigned int ima } } -template < typename TSpace, typename TKSpace > -inline -void -DGtal::Viewer3D::updateEmbeddingTextureImage(unsigned int anImageIndex, - typename Space::Point aPoint1, typename Space::Point aPoint2, - typename Space::Point aPoint3, typename Space::Point aPoint4) +template +inline void DGtal::Viewer3D::updateEmbeddingTextureImage( +unsigned int anImageIndex, typename Space::Point aPoint1, +typename Space::Point aPoint2, typename Space::Point aPoint3, +typename Space::Point aPoint4 ) { assert ( anImageIndex< myGSImageList.size()); - typename Viewer3D::TextureImage &anImage = myGSImageList.at(anImageIndex); - Display3D::updateBoundingBox(aPoint1); - Display3D::updateBoundingBox(aPoint2); - Display3D::updateBoundingBox(aPoint3); - Display3D::updateBoundingBox(aPoint4); + typename Viewer3D::TextureImage & anImage = + myGSImageList.at( anImageIndex ); + Display3D::updateBoundingBox( aPoint1 ); + Display3D::updateBoundingBox( aPoint2 ); + Display3D::updateBoundingBox( aPoint3 ); + Display3D::updateBoundingBox( aPoint4 ); anImage.updateImage3DEmbedding(aPoint1, aPoint2, aPoint3, aPoint4); } - - - -template < typename TSpace, typename TKSpace > -inline -void -DGtal::Viewer3D::TextureImage::updateImageOrientation( ImageDirection normalDir, - double xBottomLeft, double yBottomLeft, double zBottomLeft) +template +inline void +DGtal::Viewer3D::TextureImage::updateImageOrientation( +ImageDirection normalDir, double xBottomLeft, double yBottomLeft, +double zBottomLeft ) { if(normalDir==zDirection) { @@ -283,11 +261,11 @@ DGtal::Viewer3D::TextureImage::updateImageOrientation( ImageDir myDirection=normalDir; } -template < typename TSpace, typename TKSpace > -inline -void -DGtal::Viewer3D::Image2DDomainD3D::updateDomainOrientation(ImageDirection normalDir, - double xBottomLeft, double yBottomLeft, double zBottomLeft) +template +inline void +DGtal::Viewer3D::Image2DDomainD3D::updateDomainOrientation( +ImageDirection normalDir, double xBottomLeft, double yBottomLeft, +double zBottomLeft ) { if(normalDir==zDirection) { @@ -311,13 +289,9 @@ DGtal::Viewer3D::Image2DDomainD3D::updateDomainOrientation(Imag myDirection=normalDir; } - -template < typename TSpace, typename TKSpace > -inline -void -DGtal::Viewer3D::Image2DDomainD3D::translateDomain (double xTranslation, - double yTranslation, - double zTranslation) +template +inline void DGtal::Viewer3D::Image2DDomainD3D::translateDomain( +double xTranslation, double yTranslation, double zTranslation ) { point1[0] += xTranslation; point1[1] += yTranslation; point1[2] += zTranslation; point2[0] += xTranslation; point2[1] += yTranslation; point2[2] += zTranslation; @@ -325,37 +299,38 @@ DGtal::Viewer3D::Image2DDomainD3D::translateDomain (double xTra point4[0] += xTranslation; point4[1] += yTranslation; point4[2] += zTranslation; } - -template < typename TSpace, typename TKSpace > -template < typename TDomain> -void -DGtal::Viewer3D::addImage2DDomainD3D(const TDomain &aDomain, - std::string mode, - const DGtal::Color &aColor) +template +template +void DGtal::Viewer3D::addImage2DDomainD3D( +const TDomain & aDomain, std::string mode, const DGtal::Color & aColor ) { - typename DGtal::Viewer3D::Image2DDomainD3D anImageDomain(aDomain); + typename DGtal::Viewer3D::Image2DDomainD3D anImageDomain( + aDomain ); anImageDomain.color = aColor; anImageDomain.myMode = mode; - anImageDomain.myLineSetIndex=Viewer3D::myLineSetList.size(); + anImageDomain.myLineSetIndex = + Viewer3D::myLineSetList.size(); myImageDomainList.push_back(anImageDomain); - Display3D::updateBoundingBox(anImageDomain.point1); - Display3D::updateBoundingBox(anImageDomain.point2); - Display3D::updateBoundingBox(anImageDomain.point3); - Display3D::updateBoundingBox(anImageDomain.point4); + Display3D::updateBoundingBox( anImageDomain.point1 ); + Display3D::updateBoundingBox( anImageDomain.point2 ); + Display3D::updateBoundingBox( anImageDomain.point3 ); + Display3D::updateBoundingBox( anImageDomain.point4 ); - std::vector::LineD3D> vectLines= compute2DDomainLineRepresentation(anImageDomain); - Viewer3D::myLineSetList.push_back(vectLines); + std::vector::LineD3D> vectLines = + compute2DDomainLineRepresentation( anImageDomain ); + Viewer3D::myLineSetList.push_back( vectLines ); } - -template < typename TSpace, typename TKSpace > -inline -std::vector::LineD3D> -DGtal::Viewer3D::compute2DDomainLineRepresentation( typename DGtal::Viewer3D::Image2DDomainD3D &anImageDomain ) +template +inline std::vector::LineD3D> +DGtal::Viewer3D::compute2DDomainLineRepresentation( +typename DGtal::Viewer3D::Image2DDomainD3D & anImageDomain ) { - std::vector::LineD3D> vectLinesResu= compute2DDomainLineRepresentation(anImageDomain, 0.05); - std::vector::LineD3D> vectLinesVerso= compute2DDomainLineRepresentation(anImageDomain, -0.05); + std::vector::LineD3D> + vectLinesResu = compute2DDomainLineRepresentation( anImageDomain, 0.05 ); + std::vector::LineD3D> + vectLinesVerso = compute2DDomainLineRepresentation( anImageDomain, -0.05 ); for(unsigned int i=0; i::compute2DDomainLineRepresentation( typename DG return vectLinesResu; } - -template < typename TSpace, typename TKSpace > -inline -std::vector::LineD3D> -DGtal::Viewer3D::compute2DDomainLineRepresentation(typename DGtal::Viewer3D::Image2DDomainD3D &anImageDomain, double delta ) +template +inline std::vector::LineD3D> +DGtal::Viewer3D::compute2DDomainLineRepresentation( +typename DGtal::Viewer3D::Image2DDomainD3D & anImageDomain, +double delta ) { std::vector::LineD3D> aLineSet; typename Viewer3D::LineD3D aLine; @@ -498,25 +473,25 @@ DGtal::Viewer3D::compute2DDomainLineRepresentation(typename DGt return aLineSet; } - -template < typename TSpace, typename TKSpace > -inline -void -DGtal::Viewer3D::updateAn2DDomainOrientation(unsigned int domainIndex, - double xPosition, double yPosition, - double zPosition, ImageDirection newDirection) +template +inline void DGtal::Viewer3D::updateAn2DDomainOrientation( +unsigned int domainIndex, double xPosition, double yPosition, double zPosition, +ImageDirection newDirection ) { ASSERT( domainIndex < myImageDomainList.size()); - typename Viewer3D::Image2DDomainD3D &aDomain = myImageDomainList.at(domainIndex); + typename Viewer3D::Image2DDomainD3D & aDomain = + myImageDomainList.at( domainIndex ); - Display3D::updateBoundingBox(aDomain.point1); - Display3D::updateBoundingBox(aDomain.point2); - Display3D::updateBoundingBox(aDomain.point3); - Display3D::updateBoundingBox(aDomain.point4); + Display3D::updateBoundingBox( aDomain.point1 ); + Display3D::updateBoundingBox( aDomain.point2 ); + Display3D::updateBoundingBox( aDomain.point3 ); + Display3D::updateBoundingBox( aDomain.point4 ); aDomain.updateDomainOrientation(newDirection, xPosition, yPosition, zPosition); - std::vector::LineD3D> vectNewLines= compute2DDomainLineRepresentation(aDomain); - std::vector::LineD3D> &vectLines = Viewer3D::myLineSetList.at(aDomain.myLineSetIndex); + std::vector::LineD3D> vectNewLines = + compute2DDomainLineRepresentation( aDomain ); + std::vector::LineD3D> & vectLines = + Viewer3D::myLineSetList.at( aDomain.myLineSetIndex ); vectLines.clear(); for(unsigned int i=0; i::updateAn2DDomainOrientation(unsigned int domai } - -template < typename TSpace, typename TKSpace > -inline -void -DGtal::Viewer3D::translateAn2DDomain(unsigned int domainIndex, double xTranslation, double yTranslation, double zTranslation) +template +inline void DGtal::Viewer3D::translateAn2DDomain( +unsigned int domainIndex, double xTranslation, double yTranslation, +double zTranslation ) { - typename Viewer3D::Image2DDomainD3D &anDomain = myImageDomainList.at(domainIndex); + typename Viewer3D::Image2DDomainD3D & anDomain = + myImageDomainList.at( domainIndex ); anDomain.translateDomain(xTranslation, yTranslation, zTranslation); - Display3D::updateBoundingBox(anDomain.point1); - Display3D::updateBoundingBox(anDomain.point2); - Display3D::updateBoundingBox(anDomain.point3); - Display3D::updateBoundingBox(anDomain.point4); + Display3D::updateBoundingBox( anDomain.point1 ); + Display3D::updateBoundingBox( anDomain.point2 ); + Display3D::updateBoundingBox( anDomain.point3 ); + Display3D::updateBoundingBox( anDomain.point4 ); - std::vector::LineD3D> &vectLines = Viewer3D::myLineSetList.at(anDomain.myLineSetIndex); + std::vector::LineD3D> & vectLines = + Viewer3D::myLineSetList.at( anDomain.myLineSetIndex ); for(unsigned int i=0; i::LineD3D &aLine = vectLines.at(i); + typename DGtal::Display3D::LineD3D & aLine = + vectLines.at( i ); aLine.point1[0]=aLine.point1[0]+xTranslation; aLine.point1[1]=aLine.point1[1]+yTranslation; aLine.point1[2]=aLine.point1[2]+zTranslation; aLine.point2[0]=aLine.point2[0]+xTranslation; aLine.point2[1]=aLine.point2[1]+yTranslation; aLine.point2[2]=aLine.point2[2]+zTranslation; } } -template < typename TSpace, typename TKSpace > -inline -std::string +template +inline std::string DGtal::Viewer3D::TextureImage::className() const { return "TextureImage"; } template -inline -DGtal::Viewer3D & -DGtal::Viewer3D::operator<<(const DGtal::Color & aColor) +inline DGtal::Viewer3D & DGtal::Viewer3D:: +operator<<( const DGtal::Color & aColor ) { myDefaultColor=aColor; return *this; } template -inline -DGtal::Viewer3D & -DGtal::Viewer3D::operator<<(const typename Viewer3D::StreamKey & key) +inline DGtal::Viewer3D & DGtal::Viewer3D:: +operator<<( const typename Viewer3D::StreamKey & key ) { switch (key) { @@ -580,7 +554,7 @@ DGtal::Viewer3D::operator<<(const typename Viewer3D::shiftSurfelVisu: - Viewer3D::myCurrentfShiftVisuPrisms+=0.3; + Viewer3D::myCurrentfShiftVisuPrisms += 0.3; break; } return *this; @@ -588,13 +562,12 @@ DGtal::Viewer3D::operator<<(const typename Viewer3D template -inline -DGtal::Viewer3D & -DGtal::Viewer3D::operator<<( const TDrawableWithViewer3D & object ) +inline DGtal::Viewer3D & DGtal::Viewer3D:: +operator<<( const TDrawableWithViewer3D & object ) { BOOST_CONCEPT_ASSERT((concepts::CDrawableWithViewer3D< TDrawableWithViewer3D, Space, KSpace >)); - DGtal::Viewer3DFactory::draw(*this, object); + DGtal::Viewer3DFactory::draw( *this, object ); return *this; } @@ -603,10 +576,8 @@ DGtal::Viewer3D::operator<<( const TDrawableWithViewer3D & obje // Implementation of inline functions and external operators // template -inline -std::ostream& -DGtal::operator<< ( std::ostream & out, - const Viewer3D & object ) +inline std::ostream & DGtal:: +operator<<( std::ostream & out, const Viewer3D & object ) { object.selfDisplay ( out ); return out; @@ -632,42 +603,41 @@ DGtal::operator<< ( std::ostream & out, // end of surcharge // /////////////////////////////////////////////////////////////////////////////// -template< typename TSpace, typename TKSpace> -inline -void -DGtal::Viewer3D::drawWithNames() +template +inline void DGtal::Viewer3D::drawWithNames() { // JOL: 2014/10/15. This method is called only when the user tries // to select some graphic object through QGLViewer. By default, // selection is left clic + shift key. // JOL: 2014/10/15. This is my addition for interacting with // quads. Seems to work well. - if ( myExtension != 0 ) myExtension->drawWithNames( *this ); + if ( myExtension != 0 ) + myExtension->drawWithNames( *this ); glCallList ( myQuadsMapId ); glCallList ( myCubesMapId ); - - for ( unsigned int i=0; i::myLineSetList.size(); i++ ) - { - glCallList ( myLineSetListId+i ); + for ( unsigned int i = 0; i < Viewer3D::myLineSetList.size(); + i++ ) + { + glCallList( myLineSetListId + i ); } - for ( unsigned int i=0; i::myBallSetList.size(); i++ ) + for ( unsigned int i = 0; + i < Viewer3D::myBallSetList.size(); i++ ) { glCallList(myBallSetListId+i); } } -template< typename TSpace, typename TKSpace> -inline -void -DGtal::Viewer3D::draw() +template +inline void DGtal::Viewer3D::draw() { - if ( myExtension != 0 ) myExtension->draw( *this ); - + if ( myExtension != 0 ) + myExtension->draw( *this ); + glPushMatrix(); glMultMatrixd ( manipulatedFrame()->matrix() ); glPushMatrix(); @@ -684,20 +654,23 @@ DGtal::Viewer3D::draw() glLightfv(GL_LIGHT0, GL_POSITION, myLightPosition); unsigned int i = 0; - typename vector< typename Viewer3D::ClippingPlaneD3D >::const_iterator it = Viewer3D::myClippingPlaneList.begin(); - + typename vector< + typename Viewer3D::ClippingPlaneD3D>::const_iterator it = + Viewer3D::myClippingPlaneList.begin(); + // OpenGL can't draw more than GL_MAX_CLIP_PLANES clipping plane - while ( i < GL_MAX_CLIP_PLANES && it !=Viewer3D::myClippingPlaneList.end() ) - { - double eq [4]; - eq[0]=it->a; - eq[1]=it->b; - eq[2]=it->c; - eq[3]=it->d; - glEnable ( GL_CLIP_PLANE0+i ); - glClipPlane ( GL_CLIP_PLANE0+i, eq ); - i++; - it++; + while ( i < GL_MAX_CLIP_PLANES && + it != Viewer3D::myClippingPlaneList.end() ) + { + double eq[ 4 ]; + eq[ 0 ] = it->a; + eq[ 1 ] = it->b; + eq[ 2 ] = it->c; + eq[ 3 ] = it->d; + glEnable( GL_CLIP_PLANE0 + i ); + glClipPlane( GL_CLIP_PLANE0 + i, eq ); + i++; + it++; } if (i == GL_MAX_CLIP_PLANES) { @@ -733,13 +706,14 @@ DGtal::Viewer3D::draw() } - - for ( unsigned int j=0; j< Viewer3D::myLineSetList.size(); j++ ) + for ( unsigned int j = 0; + j < Viewer3D::myLineSetList.size(); j++ ) { - if ( Viewer3D::myLineSetList.at ( j ).size() !=0 ) - { - glLineWidth ( max(myGLLineMinWidth, - Viewer3D::myLineSetList.at ( j ).at ( 0 ).width )) ; + if ( Viewer3D::myLineSetList.at( j ).size() != 0 ) + { + glLineWidth( + max( myGLLineMinWidth, + Viewer3D::myLineSetList.at( j ).at( 0 ).width ) ); } glCallList(myLineSetListId+j); } @@ -747,30 +721,33 @@ DGtal::Viewer3D::draw() glCallList(myPrismListId); glCallList( myCubesMapId ); - - for ( unsigned int j=0; j< Viewer3D::myBallSetList.size(); j++ ) + for ( unsigned int j = 0; j < Viewer3D::myBallSetList.size(); + j++ ) + { + if ( myUseGLPointsForBalls ) { - if(myUseGLPointsForBalls) - { - if ( Viewer3D::myBallSetList.at ( j ).size() !=0 ) - { - glPointSize ( max(myGLPointMinWidth, - ( Viewer3D::myBallSetList.at ( j ).at ( 0 ).radius ) )); - } - } - else - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); - - glCallList(myBallSetListId+j); - glUpdateLightRenderingMode(); + if ( Viewer3D::myBallSetList.at( j ).size() != 0 ) + { + glPointSize( max( + myGLPointMinWidth, + ( Viewer3D::myBallSetList.at( j ).at( 0 ).radius ) ) ); + } + } + else + glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE ); + + glCallList( myBallSetListId + j ); + glUpdateLightRenderingMode(); } glDisable(GL_CULL_FACE); glCallList(myQuadsMapId); if(myViewWire) { - glLineWidth ( max(myGLLineMinWidth,Viewer3D::myMeshDefaultLineWidth /distCam )); + glLineWidth( + max( myGLLineMinWidth, + Viewer3D::myMeshDefaultLineWidth / distCam ) ); glCallList(myQuadsMapWiredId); } @@ -778,8 +755,9 @@ DGtal::Viewer3D::draw() glCallList(myTriangleSetListId); if(myViewWire) { - glLineWidth ( max(myGLLineMinWidth, - Viewer3D::myMeshDefaultLineWidth /distCam )); + glLineWidth( + max( myGLLineMinWidth, + Viewer3D::myMeshDefaultLineWidth / distCam ) ); glCallList(myTriangleSetListWiredId); } @@ -787,8 +765,9 @@ DGtal::Viewer3D::draw() glCallList(myPolygonSetListId); if(myViewWire) { - glLineWidth (max(myGLLineMinWidth, - Viewer3D::myMeshDefaultLineWidth /distCam )); + glLineWidth( + max( myGLLineMinWidth, + Viewer3D::myMeshDefaultLineWidth / distCam ) ); glCallList(myPolygonSetListWiredId); } @@ -800,27 +779,23 @@ DGtal::Viewer3D::draw() glPopMatrix(); } - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::selfDisplay ( std::ostream & out ) const +template +void DGtal::Viewer3D::selfDisplay( std::ostream & out ) const { out << "[Viewer3D]"; } - -template< typename TSpace, typename TKSpace> -bool -DGtal::Viewer3D::isValid() const +template +bool DGtal::Viewer3D::isValid() const { return true; } -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::init() +template +void DGtal::Viewer3D::init() { - if ( myExtension != 0 ) myExtension->init( *this ); + if ( myExtension != 0 ) + myExtension->init( *this ); myAutoSaveState = false; myIsMovingLight = false; myLigthRotationStep = 0.01; @@ -848,35 +823,41 @@ DGtal::Viewer3D::init() glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); - - Viewer3D::myMeshDefaultLineWidth=10.0; + + Viewer3D::myMeshDefaultLineWidth = 10.0; myNbListe=0; myViewWire=false; setBackgroundColor ( QColor ( 217, 228, 255 ) ); setForegroundColor ( QColor ( 217, 22, 25 ) ); - - Viewer3D::createNewCubeList ( ); + + Viewer3D::createNewCubeList(); vector::LineD3D> listeLine; - Viewer3D::myLineSetList.push_back ( listeLine ); + Viewer3D::myLineSetList.push_back( listeLine ); vector::BallD3D> listeBall; - Viewer3D::myBallSetList.push_back ( listeBall ); - Viewer3D::myCurrentFillColor = Color ( 220, 220, 220 ); - Viewer3D::myCurrentLineColor = Color ( 22, 22, 222, 50 ); + Viewer3D::myBallSetList.push_back( listeBall ); + Viewer3D::myCurrentFillColor = Color( 220, 220, 220 ); + Viewer3D::myCurrentLineColor = Color( 22, 22, 222, 50 ); myDefaultBackgroundColor = Color ( backgroundColor().red(), backgroundColor().green(), backgroundColor().blue() ); myIsBackgroundDefault=true; - Viewer3D::myBoundingPtLow[0]=-10.0;//numeric_limits::max( ); - Viewer3D::myBoundingPtLow[1]=-10.0;//numeric_limits::max( ); - Viewer3D::myBoundingPtLow[2]=-10.0;//numeric_limits::max( ); - - Viewer3D::myBoundingPtUp[0]=-10.0;//numeric_limits::min( ); - Viewer3D::myBoundingPtUp[1]=-10.0;//numeric_limits::min( ); - Viewer3D:: myBoundingPtUp[2]=-10.0;//numeric_limits::min( ); - Viewer3D::createNewCubeList ( ); - typename std::vector< typename Viewer3D::CubeD3D> aKSCubeList; - - Viewer3D::myCurrentfShiftVisuPrisms=0.0; - Viewer3D::myDefaultColor= Color ( 255, 255, 255 ); + Viewer3D::myBoundingPtLow[ 0 ] = + -10.0; // numeric_limits::max( ); + Viewer3D::myBoundingPtLow[ 1 ] = + -10.0; // numeric_limits::max( ); + Viewer3D::myBoundingPtLow[ 2 ] = + -10.0; // numeric_limits::max( ); + + Viewer3D::myBoundingPtUp[ 0 ] = + -10.0; // numeric_limits::min( ); + Viewer3D::myBoundingPtUp[ 1 ] = + -10.0; // numeric_limits::min( ); + Viewer3D::myBoundingPtUp[ 2 ] = + -10.0; // numeric_limits::min( ); + Viewer3D::createNewCubeList(); + typename std::vector::CubeD3D> aKSCubeList; + + Viewer3D::myCurrentfShiftVisuPrisms = 0.0; + Viewer3D::myDefaultColor = Color( 255, 255, 255 ); camera()->showEntireScene(); setKeyDescription ( Qt::Key_E, "Export the current display into OFF file (just Cube, surfel and SurfelPrism for now)." ); setKeyDescription ( Qt::Key_W, "Switch display with and without wired view of triangle and quad faces." ); @@ -890,9 +871,13 @@ DGtal::Viewer3D::init() setKeyDescription ( Qt::Key_O, "Switch the ball display mode (quad ball display (default) or OpenGL point)." ); setKeyDescription ( Qt::Key_M, "Switch the rendering mode bewteen Default, Metallic and Plastic mode." ); setKeyDescription ( Qt::Key_P, "Switch the light source position mode between the camera mode (default: the light source position is fixed according to the camera position) and scene mode (the light source position is fixed according the scene coordinate system)." ); - setKeyDescription ( Qt::Key_Z, "Move away the light source according to the scence center (move closer with SHIFT+Z)"); - setKeyDescription ( Qt::ShiftModifier+Qt::Key_Z, "Move closer the light source according to the scence center (move awya with key Z)" ); - + setKeyDescription( Qt::Key_Z, + "Move away the light source according to the scence " + "center (move closer with SHIFT+Z)" ); + setKeyDescription( Qt::ShiftModifier + Qt::Key_Z, + "Move closer the light source according to the scence " + "center (move awya with key Z)" ); + #if !defined (QGLVIEWER_VERSION) || QGLVIEWER_VERSION < 0x020500 setMouseBindingDescription((Qt::ControlModifier|Qt::ShiftModifier) + Qt::LeftButton, "move light source position defined in the main coordinate system (an x-axis (resp. y-axis) mouse move changes the azimuth (resp. inclination) angle of the light source). Note that light source is always looking at the center point (0,0,0)."); #else @@ -911,84 +896,75 @@ DGtal::Viewer3D::init() setManipulatedFrame ( new ManipulatedFrame() ); } - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::sortSurfelFromCamera() +template +void DGtal::Viewer3D::sortSurfelFromCamera() { CompFarthestVoxelFromCamera comp; comp.posCam= camera()->position(); - for (auto &mapElem: Viewer3D::myCubesMap) - - { - DGtal::trace.info() << "sort quad size" << mapElem.second.size() << std::endl; - sort ( mapElem.second.begin(), mapElem.second.end(), comp ); + for ( auto & mapElem : Viewer3D::myCubesMap ) + + { + DGtal::trace.info() << "sort quad size" << mapElem.second.size() + << std::endl; + sort( mapElem.second.begin(), mapElem.second.end(), comp ); } CompFarthestSurfelFromCamera compSurf; - DGtal::trace.info() << "sort surfel size" << Viewer3D::myPrismList.size() << std::endl; - sort ( Viewer3D::myPrismList.begin(), Viewer3D::myPrismList.end(), compSurf ); + DGtal::trace.info() << "sort surfel size" + << Viewer3D::myPrismList.size() + << std::endl; + sort( Viewer3D::myPrismList.begin(), + Viewer3D::myPrismList.end(), compSurf ); } - - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::sortTriangleFromCamera() +template +void DGtal::Viewer3D::sortTriangleFromCamera() { CompFarthestTriangleFromCamera comp; comp.posCam= camera()->position(); - for (auto &listElem: Viewer3D::myTriangleSetList) - { - sort ( listElem.begin(), listElem.end(), comp ); + for ( auto & listElem : Viewer3D::myTriangleSetList ) + { + sort( listElem.begin(), listElem.end(), comp ); } } - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::sortQuadFromCamera() +template +void DGtal::Viewer3D::sortQuadFromCamera() { CompFarthestSurfelFromCamera comp; comp.posCam= camera()->position(); - for (auto &listElem: Viewer3D::myQuadsMap) - { - DGtal::trace.info() << "sort quad size" << listElem.second.size() << std::endl; - sort ( listElem.second.begin(), listElem.second.end(), comp ); + for ( auto & listElem : Viewer3D::myQuadsMap ) + { + DGtal::trace.info() << "sort quad size" << listElem.second.size() + << std::endl; + sort( listElem.second.begin(), listElem.second.end(), comp ); } } - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::sortPolygonFromCamera() +template +void DGtal::Viewer3D::sortPolygonFromCamera() { CompFarthestPolygonFromCamera comp; comp.posCam= camera()->position(); - for (auto &listElem: Viewer3D::myPolygonSetList) - { - DGtal::trace.info() << "sort polygon size" << listElem.size() << std::endl; - sort ( listElem.begin(), listElem.end(), comp ); + for ( auto & listElem : Viewer3D::myPolygonSetList ) + { + DGtal::trace.info() << "sort polygon size" << listElem.size() << std::endl; + sort( listElem.begin(), listElem.end(), comp ); } } - - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::postSelection ( const QPoint& point ) +template +void DGtal::Viewer3D::postSelection( const QPoint & point ) { bool handled = false; if ( myExtension != 0 ) handled = myExtension->postSelection( *this, point ); - if ( handled ) return; - + if ( handled ) + return; + camera()->convertClickToLine ( point, myOrig, myDir ); bool found; this->myPosSelector= point; @@ -1010,11 +986,9 @@ DGtal::Viewer3D::postSelection ( const QPoint& point ) } } - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::updateList ( bool needToUpdateBoundingBox ) +template +void DGtal::Viewer3D::updateList( +bool needToUpdateBoundingBox ) { // glDeleteLists @@ -1031,10 +1005,12 @@ DGtal::Viewer3D::updateList ( bool needToUpdateBoundingBox ) // Storing ID for each list myCubesMapId = glGenLists(1); - myLineSetListId = glGenLists(Viewer3D::myLineSetList.size()); - myNbLineSetList = Viewer3D::myLineSetList.size(); - myBallSetListId = glGenLists(Viewer3D::myBallSetList.size()); - myNbBallSetList = Viewer3D::myBallSetList.size(); + myLineSetListId = + glGenLists( Viewer3D::myLineSetList.size() ); + myNbLineSetList = Viewer3D::myLineSetList.size(); + myBallSetListId = + glGenLists( Viewer3D::myBallSetList.size() ); + myNbBallSetList = Viewer3D::myBallSetList.size(); myTriangleSetListId = glGenLists(1); myTriangleSetListWiredId = glGenLists(1); myCubeSetListWiredId = glGenLists(1); @@ -1052,75 +1028,80 @@ DGtal::Viewer3D::updateList ( bool needToUpdateBoundingBox ) glEnable ( GL_SAMPLE_ALPHA_TO_COVERAGE_ARB ); glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + glCreateListCubesMaps( Viewer3D::myCubesMap, myCubesMapId ); - - glCreateListCubesMaps(Viewer3D::myCubesMap, myCubesMapId); - - - glCreateListQuadD3D(Viewer3D::myPrismList, myPrismListId); + glCreateListQuadD3D( Viewer3D::myPrismList, myPrismListId ); myNbListe++; - for ( unsigned int j=0; j::myLineSetList.size(); j++ ) - { - glCreateListLines(Viewer3D::myLineSetList.at(j), myLineSetListId+j); - myNbListe++; + for ( unsigned int j = 0; j < Viewer3D::myLineSetList.size(); + j++ ) + { + glCreateListLines( Viewer3D::myLineSetList.at( j ), + myLineSetListId + j ); + myNbListe++; } - for ( unsigned int j=0; j::myBallSetList.size(); j++ ) + for ( unsigned int j = 0; + j < Viewer3D::myBallSetList.size(); j++ ) { - glCreateListBalls(Viewer3D::myBallSetList.at (j), myBallSetListId+j); + glCreateListBalls( Viewer3D::myBallSetList.at( j ), + myBallSetListId + j ); myNbListe++; } // First list: quad faces. - glCreateListQuadMaps(Viewer3D::myQuadsMap, myQuadsMapId); - myNbListe++; - - // Second list: Wired version of quad face. - glCreateListQuadMapsWired(Viewer3D::myQuadsMap,myQuadsMapWiredId); - myNbListe++; - - // Third list: Triangle faces. - glCreateListTriangles( Viewer3D::myTriangleSetList, myTriangleSetListId); - myNbListe++; - - // Fourth list: Wired version of triangle face. - glCreateListTrianglesWired(Viewer3D::myTriangleSetList, myTriangleSetListWiredId); - myNbListe++; - - // Fifth list: Polygonal faces. - glCreateListPolygons(Viewer3D::myPolygonSetList, myPolygonSetListId); - myNbListe++; - - // Sixth list: Wired version of polygonal face. - glCreateListPolygonsWired(Viewer3D::myPolygonSetList, myPolygonSetListWiredId); - myNbListe++; - - - // Seventh list: Textured images. - glUpdateTextureImages(myGSImageList); - - if ( needToUpdateBoundingBox && Viewer3D::myBoundingPtChangedTag ) - { - setSceneBoundingBox ( qglviewer::Vec ( Viewer3D::myBoundingPtLow[0], - Viewer3D::myBoundingPtLow[1], - Viewer3D::myBoundingPtLow[2] ), - qglviewer::Vec ( Viewer3D::myBoundingPtUp[0], - Viewer3D::myBoundingPtUp[1], - Viewer3D::myBoundingPtUp[2] ) ); + glCreateListQuadMaps( Viewer3D::myQuadsMap, myQuadsMapId ); + myNbListe++; + + // Second list: Wired version of quad face. + glCreateListQuadMapsWired( Viewer3D::myQuadsMap, + myQuadsMapWiredId ); + myNbListe++; + + // Third list: Triangle faces. + glCreateListTriangles( Viewer3D::myTriangleSetList, + myTriangleSetListId ); + myNbListe++; + + // Fourth list: Wired version of triangle face. + glCreateListTrianglesWired( Viewer3D::myTriangleSetList, + myTriangleSetListWiredId ); + myNbListe++; + + // Fifth list: Polygonal faces. + glCreateListPolygons( Viewer3D::myPolygonSetList, + myPolygonSetListId ); + myNbListe++; + + // Sixth list: Wired version of polygonal face. + glCreateListPolygonsWired( Viewer3D::myPolygonSetList, + myPolygonSetListWiredId ); + myNbListe++; + + // Seventh list: Textured images. + glUpdateTextureImages( myGSImageList ); + + if ( needToUpdateBoundingBox && + Viewer3D::myBoundingPtChangedTag ) + { + setSceneBoundingBox( + qglviewer::Vec( Viewer3D::myBoundingPtLow[ 0 ], + Viewer3D::myBoundingPtLow[ 1 ], + Viewer3D::myBoundingPtLow[ 2 ] ), + qglviewer::Vec( Viewer3D::myBoundingPtUp[ 0 ], + Viewer3D::myBoundingPtUp[ 1 ], + Viewer3D::myBoundingPtUp[ 2 ] ) ); showEntireScene(); Viewer3D::myBoundingPtChangedTag = false; } - updateGL(); - glPopMatrix(); + updateGL(); + glPopMatrix(); } - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::glDrawGLBall (const typename Viewer3D::BallD3D &aBall ) +template +void DGtal::Viewer3D::glDrawGLBall( +const typename Viewer3D::BallD3D & aBall ) { double thetaResolution = aBall.resolution; double thetaStep= (2.0*M_PI)/thetaResolution; @@ -1150,17 +1131,17 @@ DGtal::Viewer3D::glDrawGLBall (const typename Viewer3D -void -DGtal::Viewer3D::mousePressEvent ( QMouseEvent *e ) +template +void DGtal::Viewer3D::mousePressEvent( QMouseEvent * e ) { bool handled = false; // Checks if an extension is present. if ( myExtension != 0 ) - { - handled = myExtension->mousePressEvent( *this, e ); - if ( handled ) return; - } + { + handled = myExtension->mousePressEvent( *this, e ); + if ( handled ) + return; + } if(e->modifiers() == (Qt::ControlModifier|Qt::ShiftModifier)) { @@ -1183,18 +1164,18 @@ DGtal::Viewer3D::mousePressEvent ( QMouseEvent *e ) } } -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::mouseReleaseEvent ( QMouseEvent *e ) +template +void DGtal::Viewer3D::mouseReleaseEvent( QMouseEvent * e ) { bool handled = false; // Checks if an extension is present. if ( myExtension != 0 ) - { - handled = myExtension->mouseReleaseEvent( *this, e ); - if ( handled ) return; - } - + { + handled = myExtension->mouseReleaseEvent( *this, e ); + if ( handled ) + return; + } + if(e->modifiers() == (Qt::ControlModifier|Qt::ShiftModifier) || myIsMovingLight){ myIsMovingLight=false; updateGL(); @@ -1203,23 +1184,23 @@ DGtal::Viewer3D::mouseReleaseEvent ( QMouseEvent *e ) } } -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::mouseMoveEvent ( QMouseEvent *e ) +template +void DGtal::Viewer3D::mouseMoveEvent( QMouseEvent * e ) { bool handled = false; // Checks if an extension is present. if ( myExtension != 0 ) - { - handled = myExtension->mouseMoveEvent( *this, e ); - if ( handled ) return; - } + { + handled = myExtension->mouseMoveEvent( *this, e ); + if ( handled ) + return; + } if(e->modifiers() == (Qt::ControlModifier|Qt::ShiftModifier)){ - int varX = e->x() - myRefMouseXPos; - int varY = e->y() - myRefMouseYPos; - myLightPhi -= varY*myLigthRotationStep; - myLightTheta -= varX*myLigthRotationStep/2.0; + int varX = e->x() - myRefMouseXPos; + int varY = e->y() - myRefMouseYPos; + myLightPhi -= varY * myLigthRotationStep; + myLightTheta -= varX * myLigthRotationStep / 2.0; myLightPosition[0] = myLightR*cos(myLightTheta)*cos(myLightPhi); myLightPosition[1] = myLightR*cos(myLightTheta)*sin(myLightPhi); myLightPosition[2] = myLightR*sin(myLightTheta); @@ -1235,20 +1216,17 @@ DGtal::Viewer3D::mouseMoveEvent ( QMouseEvent *e ) } } - - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::keyPressEvent ( QKeyEvent *e ) +template +void DGtal::Viewer3D::keyPressEvent( QKeyEvent * e ) { bool handled = false; // Checks if an extension is present. if ( myExtension != 0 ) - { - handled = myExtension->keyPressEvent( *this, e ); - if ( handled ) return; - } + { + handled = myExtension->keyPressEvent( *this, e ); + if ( handled ) + return; + } if( e->key() == Qt::Key_D) { @@ -1260,7 +1238,7 @@ DGtal::Viewer3D::keyPressEvent ( QKeyEvent *e ) if( e->key() == Qt::Key_E) { trace.info() << "Exporting mesh..." ; - operator>> (*this, "exportedMesh.off"); + operator>>( *this, "exportedMesh.off" ); trace.info() << "[done]"<< endl ; } if( e->key() == Qt::Key_M) @@ -1291,44 +1269,43 @@ DGtal::Viewer3D::keyPressEvent ( QKeyEvent *e ) updateList(false); updateGL(); } - if( e->key() == Qt::Key_Z) + if ( e->key() == Qt::Key_Z ) { - if( myLightPositionFixToCamera ) - { - updateLightCoordsFromCamera(); - } - myLightR = sqrt( myLightPosition[0]* myLightPosition[0]+ - myLightPosition[1]* myLightPosition[1]+ - myLightPosition[2]* myLightPosition[2]); - myLightTheta = asin( myLightPosition[2]/myLightR); - myLightPhi = atan2( myLightPosition[1], myLightPosition[0]); - - stringstream ss; - if(e->modifiers()==Qt::ShiftModifier) - { - myLightR += 5.0; - ss << "Move away light source at distance: " << myLightR; - } + if ( myLightPositionFixToCamera ) + { + updateLightCoordsFromCamera(); + } + myLightR = sqrt( myLightPosition[ 0 ] * myLightPosition[ 0 ] + + myLightPosition[ 1 ] * myLightPosition[ 1 ] + + myLightPosition[ 2 ] * myLightPosition[ 2 ] ); + myLightTheta = asin( myLightPosition[ 2 ] / myLightR ); + myLightPhi = atan2( myLightPosition[ 1 ], myLightPosition[ 0 ] ); + + stringstream ss; + if ( e->modifiers() == Qt::ShiftModifier ) + { + myLightR += 5.0; + ss << "Move away light source at distance: " << myLightR; + } else - { - myLightR -= 5.0; - ss << "Move closer light source at distance: " << myLightR; - } - displayMessage(QString(ss.str().c_str()), 3000); - myLightPosition[0] = myLightR*cos(myLightTheta)*cos(myLightPhi); - myLightPosition[1] = myLightR*cos(myLightTheta)*sin(myLightPhi); - myLightPosition[2] = myLightR*sin(myLightTheta); - if(myLightPositionFixToCamera) - { - updateRelativeCameraFromLightPosition(); - } - myIsMovingLight=true; - glLightfv(GL_LIGHT0, GL_POSITION, myLightPosition); + { + myLightR -= 5.0; + ss << "Move closer light source at distance: " << myLightR; + } + displayMessage( QString( ss.str().c_str() ), 3000 ); + myLightPosition[ 0 ] = myLightR * cos( myLightTheta ) * cos( myLightPhi ); + myLightPosition[ 1 ] = myLightR * cos( myLightTheta ) * sin( myLightPhi ); + myLightPosition[ 2 ] = myLightR * sin( myLightTheta ); + if ( myLightPositionFixToCamera ) + { + updateRelativeCameraFromLightPosition(); + } + myIsMovingLight = true; + glLightfv( GL_LIGHT0, GL_POSITION, myLightPosition ); updateGL(); } - - if ( ( e->key() ==Qt::Key_P ) ) + if ( ( e->key() == Qt::Key_P ) ) { myLightPositionFixToCamera =! myLightPositionFixToCamera; updateLightCoordsFromCamera(); @@ -1447,16 +1424,13 @@ DGtal::Viewer3D::keyPressEvent ( QKeyEvent *e ) QGLViewer::keyPressEvent ( e ); } - - - -template< typename TSpace, typename TKSpace> -QString -DGtal::Viewer3D::helpString() const +template +QString DGtal::Viewer3D::helpString() const { QString text; - if ( myExtension != 0 ) text += myExtension->helpString( *this ); - + if ( myExtension != 0 ) + text += myExtension->helpString( *this ); + text += "

Viewer3D

"; text += "Use the mouse to move the camera around the object. "; text += "You can respectively revolve around, zoom and translate with the three mouse buttons. "; @@ -1475,13 +1449,11 @@ DGtal::Viewer3D::helpString() const return text; } - - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::glCreateListCubesMaps(const typename DGtal::Display3D::CubesMap &aCubeMap, - unsigned int idList){ +template +void DGtal::Viewer3D::glCreateListCubesMaps( +const typename DGtal::Display3D::CubesMap & aCubeMap, +unsigned int idList ) +{ glNewList ( idList , GL_COMPILE ); for (auto &mapElem: aCubeMap) @@ -1563,12 +1535,10 @@ DGtal::Viewer3D::glCreateListCubesMaps(const typename DGtal::Di } - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::glCreateListQuadD3D(const VectorQuad &aVectQuad, - unsigned int idList){ +template +void DGtal::Viewer3D::glCreateListQuadD3D( +const VectorQuad & aVectQuad, unsigned int idList ) +{ glNewList ( idList, GL_COMPILE ); glPushName ( myNbListe ); glEnable ( GL_DEPTH_TEST ); @@ -1592,12 +1562,10 @@ DGtal::Viewer3D::glCreateListQuadD3D(const VectorQuad &aVectQua glEndList(); } - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::glCreateListLines(const VectorLine &aVectLine, - unsigned int idList){ +template +void DGtal::Viewer3D::glCreateListLines( +const VectorLine & aVectLine, unsigned int idList ) +{ glNewList ( idList, GL_COMPILE ); glDisable ( GL_LIGHTING ); glPushName ( myNbListe ); @@ -1614,12 +1582,10 @@ DGtal::Viewer3D::glCreateListLines(const VectorLine &aVectLine, glEndList(); } - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::glCreateListBalls(const VectorBall &aVectBall, - unsigned int idList){ +template +void DGtal::Viewer3D::glCreateListBalls( +const VectorBall & aVectBall, unsigned int idList ) +{ if(myUseGLPointsForBalls) { glNewList ( idList, GL_COMPILE ); @@ -1655,13 +1621,11 @@ DGtal::Viewer3D::glCreateListBalls(const VectorBall &aVectBall, } } - - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::glCreateListQuadMaps(const typename DGtal::Display3D::QuadsMap &aQuadMap, - unsigned int idList){ +template +void DGtal::Viewer3D::glCreateListQuadMaps( +const typename DGtal::Display3D::QuadsMap & aQuadMap, +unsigned int idList ) +{ glNewList ( idList, GL_COMPILE ); for (auto & mapElem: aQuadMap) { @@ -1709,13 +1673,11 @@ DGtal::Viewer3D::glCreateListQuadMaps(const typename DGtal::Dis glEndList(); } - - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::glCreateListQuadMapsWired(const typename DGtal::Display3D::QuadsMap &aQuadMap, - unsigned int idList){ +template +void DGtal::Viewer3D::glCreateListQuadMapsWired( +const typename DGtal::Display3D::QuadsMap & aQuadMap, +unsigned int idList ) +{ glNewList ( idList, GL_COMPILE ); glPushName ( myNbListe ); glDisable ( GL_LIGHTING ); @@ -1726,24 +1688,24 @@ DGtal::Viewer3D::glCreateListQuadMapsWired(const typename DGtal for(auto const &q: mapElem.second) { glColor4ub ( 150.0,150.0,150.0,255.0 ); - glColor4ub ( Viewer3D::myCurrentLineColor.red(), - Viewer3D::myCurrentLineColor.green(), - Viewer3D::myCurrentLineColor.blue(), - Viewer3D::myCurrentLineColor.alpha() ); + glColor4ub( Viewer3D::myCurrentLineColor.red(), + Viewer3D::myCurrentLineColor.green(), + Viewer3D::myCurrentLineColor.blue(), + Viewer3D::myCurrentLineColor.alpha() ); glVertex3f ( q.point1[0], q.point1[1], q.point1[2] ); glVertex3f ( q.point2[0], q.point2[1], q.point2[2] ); glVertex3f ( q.point2[0], q.point2[1], q.point2[2] ); - glColor4ub ( Viewer3D::myCurrentLineColor.red(), - Viewer3D::myCurrentLineColor.green(), - Viewer3D::myCurrentLineColor.blue(), - Viewer3D::myCurrentLineColor.alpha() ); + glColor4ub( Viewer3D::myCurrentLineColor.red(), + Viewer3D::myCurrentLineColor.green(), + Viewer3D::myCurrentLineColor.blue(), + Viewer3D::myCurrentLineColor.alpha() ); glVertex3f ( q.point3[0], q.point3[1], q.point3[2] ); glVertex3f ( q.point3[0], q.point3[1], q.point3[2] ); glVertex3f ( q.point4[0], q.point4[1], q.point4[2] ); - glColor4ub ( Viewer3D::myCurrentLineColor.red(), - Viewer3D::myCurrentLineColor.green(), - Viewer3D::myCurrentLineColor.blue(), - Viewer3D::myCurrentLineColor.alpha() ); + glColor4ub( Viewer3D::myCurrentLineColor.red(), + Viewer3D::myCurrentLineColor.green(), + Viewer3D::myCurrentLineColor.blue(), + Viewer3D::myCurrentLineColor.alpha() ); glVertex3f ( q.point4[0], q.point4[1], q.point4[2] ); glVertex3f ( q.point1[0], q.point1[1], q.point1[2] ); } @@ -1753,11 +1715,10 @@ DGtal::Viewer3D::glCreateListQuadMapsWired(const typename DGtal } - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::glCreateListTriangles(const std::vector &aVectTriangle, - unsigned int idList){ +template +void DGtal::Viewer3D::glCreateListTriangles( +const std::vector & aVectTriangle, unsigned int idList ) +{ glNewList ( idList, GL_COMPILE ); glPushName ( myNbListe ); glEnable ( GL_LIGHTING ); @@ -1777,11 +1738,10 @@ DGtal::Viewer3D::glCreateListTriangles(const std::vector -void -DGtal::Viewer3D::glCreateListTrianglesWired(const std::vector &aVectTriangle, - unsigned int idList){ +template +void DGtal::Viewer3D::glCreateListTrianglesWired( +const std::vector & aVectTriangle, unsigned int idList ) +{ glNewList ( idList, GL_COMPILE ); glPushName ( myNbListe ); glDisable ( GL_LIGHTING ); @@ -1790,10 +1750,10 @@ DGtal::Viewer3D::glCreateListTrianglesWired(const std::vector::myCurrentLineColor.red(), - Viewer3D::myCurrentLineColor.green(), - Viewer3D::myCurrentLineColor.blue(), - Viewer3D::myCurrentLineColor.alpha() ); + glColor4ub( Viewer3D::myCurrentLineColor.red(), + Viewer3D::myCurrentLineColor.green(), + Viewer3D::myCurrentLineColor.blue(), + Viewer3D::myCurrentLineColor.alpha() ); glVertex3f (t.point1[0],t.point1[1],t.point1[2] ); glVertex3f (t.point2[0],t.point2[1],t.point2[2] ); glVertex3f (t.point2[0],t.point2[1],t.point2[2] ); @@ -1807,12 +1767,10 @@ DGtal::Viewer3D::glCreateListTrianglesWired(const std::vector -void -DGtal::Viewer3D::glCreateListPolygons(const std::vector &aVectPolygon, - unsigned int idList){ +template +void DGtal::Viewer3D::glCreateListPolygons( +const std::vector & aVectPolygon, unsigned int idList ) +{ glNewList ( idList, GL_COMPILE ); glPushName ( myNbListe ); glEnable ( GL_LIGHTING ); @@ -1834,12 +1792,10 @@ DGtal::Viewer3D::glCreateListPolygons(const std::vector -void -DGtal::Viewer3D::glCreateListPolygonsWired(const std::vector &aVectPolygon, - unsigned int idList){ +template +void DGtal::Viewer3D::glCreateListPolygonsWired( +const std::vector & aVectPolygon, unsigned int idList ) +{ glNewList ( idList, GL_COMPILE ); glPushName ( myNbListe ); glDisable ( GL_LIGHTING ); @@ -1848,10 +1804,10 @@ DGtal::Viewer3D::glCreateListPolygonsWired(const std::vector::myCurrentLineColor.red(), - Viewer3D::myCurrentLineColor.green(), - Viewer3D::myCurrentLineColor.blue() , - Viewer3D::myCurrentLineColor.alpha() ); + glColor4ub( Viewer3D::myCurrentLineColor.red(), + Viewer3D::myCurrentLineColor.green(), + Viewer3D::myCurrentLineColor.blue(), + Viewer3D::myCurrentLineColor.alpha() ); for(unsigned int j=0;j < (p.vertices).size();j++) { glVertex3f ( (p.vertices).at(j)[0], (p.vertices).at(j)[1], (p.vertices).at ( j )[2] ); @@ -1865,11 +1821,10 @@ DGtal::Viewer3D::glCreateListPolygonsWired(const std::vector -void -DGtal::Viewer3D::glUpdateTextureImages(const VectorTextureImage &aVectImage){ +template +void DGtal::Viewer3D::glUpdateTextureImages( +const VectorTextureImage & aVectImage ) +{ for(unsigned int j=0; j::glUpdateTextureImages(const VectorTextureImag myVectTextureImage.clear(); for(unsigned int j=0; j::TextureImage aGSImage = aVectImage.at(j); + typename Viewer3D::TextureImage aGSImage = + aVectImage.at( j ); GLTextureImage textureImg(aGSImage); glGenTextures(1, &textureImg.myTextureName); @@ -1887,22 +1843,24 @@ DGtal::Viewer3D::glUpdateTextureImages(const VectorTextureImag glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - if(textureImg.myMode==Viewer3D::GrayScaleMode) - { - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, textureImg.myBufferWidth, textureImg.myBufferHeight, 0, - GL_LUMINANCE, GL_UNSIGNED_BYTE, textureImg.myTextureImageBufferGS); - }else if(textureImg.myMode==Viewer3D::RGBMode) - { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureImg.myBufferWidth, textureImg.myBufferHeight, 0, - GL_RGB, GL_UNSIGNED_BYTE, textureImg.myTextureImageBufferRGB); + if ( textureImg.myMode == Viewer3D::GrayScaleMode ) + { + glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE, textureImg.myBufferWidth, + textureImg.myBufferHeight, 0, GL_LUMINANCE, + GL_UNSIGNED_BYTE, textureImg.myTextureImageBufferGS ); + } + else if ( textureImg.myMode == Viewer3D::RGBMode ) + { + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, textureImg.myBufferWidth, + textureImg.myBufferHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, + textureImg.myTextureImageBufferRGB ); } myVectTextureImage.push_back(textureImg); } } -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::glUpdateLightRenderingMode() const +template +void DGtal::Viewer3D::glUpdateLightRenderingMode() const { if(myIsDoubleFaceRendering) glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); @@ -1910,11 +1868,10 @@ DGtal::Viewer3D::glUpdateLightRenderingMode() const glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); } - - -template< typename TSpace, typename TKSpace> +template QDomElement -DGtal::Viewer3D::domElement(const QString& name, QDomDocument& document) const +DGtal::Viewer3D::domElement( const QString & name, + QDomDocument & document ) const { // Creates a custom node for a light position QDomElement deRendering = document.createElement("Rendering"); @@ -1930,11 +1887,9 @@ DGtal::Viewer3D::domElement(const QString& name, QDomDocument& return res; } - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::initFromDOMElement(const QDomElement& element) +template +void DGtal::Viewer3D::initFromDOMElement( +const QDomElement & element ) { // Restore standard state QGLViewer::initFromDOMElement(element); @@ -1970,10 +1925,9 @@ DGtal::Viewer3D::initFromDOMElement(const QDomElement& element) updateGL(); } - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::closeEvent ( QCloseEvent * e ){ +template +void DGtal::Viewer3D::closeEvent( QCloseEvent * e ) +{ if (myAutoSaveState) { saveStateToFile(); @@ -1981,27 +1935,25 @@ DGtal::Viewer3D::closeEvent ( QCloseEvent * e ){ QGLWidget::closeEvent(e); } -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::setGLDoubleRenderingMode(bool doubleSidedRendering) +template +void DGtal::Viewer3D::setGLDoubleRenderingMode( +bool doubleSidedRendering ) { myIsDoubleFaceRendering = doubleSidedRendering; glUpdateLightRenderingMode(); } - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::setGLMaterialShininessCoefficient(const GLfloat matShininessCoeff) +template +void DGtal::Viewer3D::setGLMaterialShininessCoefficient( +const GLfloat matShininessCoeff ) { myMaterialShininessCoeff = matShininessCoeff; updateGL(); } - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::setGLLightAmbientCoefficients(const GLfloat lightAmbientCoeffs [4]) +template +void DGtal::Viewer3D::setGLLightAmbientCoefficients( +const GLfloat lightAmbientCoeffs[ 4 ] ) { myLightAmbientCoeffs[0] = lightAmbientCoeffs[0]; myLightAmbientCoeffs[1] = lightAmbientCoeffs[1]; @@ -2010,10 +1962,9 @@ DGtal::Viewer3D::setGLLightAmbientCoefficients(const GLfloat li updateGL(); } - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::setGLLightDiffuseCoefficients(const GLfloat lightDiffuseCoeffs [4]) +template +void DGtal::Viewer3D::setGLLightDiffuseCoefficients( +const GLfloat lightDiffuseCoeffs[ 4 ] ) { myLightDiffuseCoeffs[0] = lightDiffuseCoeffs[0]; myLightDiffuseCoeffs[1] = lightDiffuseCoeffs[1]; @@ -2022,19 +1973,16 @@ DGtal::Viewer3D::setGLLightDiffuseCoefficients(const GLfloat li updateGL(); } - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::setUseGLPointForBalls(const bool useOpenGLPt) +template +void DGtal::Viewer3D::setUseGLPointForBalls( +const bool useOpenGLPt ) { myUseGLPointsForBalls = useOpenGLPt; } - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::updateRenderingCoefficients(const RenderingMode aRenderMode, bool displayState) +template +void DGtal::Viewer3D::updateRenderingCoefficients( +const RenderingMode aRenderMode, bool displayState ) { stringstream ss; ss << "Rendering mode "; @@ -2076,11 +2024,9 @@ DGtal::Viewer3D::updateRenderingCoefficients(const RenderingMod updateGL(); } - - -template< typename TSpace, typename TKSpace> -void -DGtal::Viewer3D::setGLLightSpecularCoefficients(const GLfloat lightSpecularCoeffs [4]) +template +void DGtal::Viewer3D::setGLLightSpecularCoefficients( +const GLfloat lightSpecularCoeffs[ 4 ] ) { myLightSpecularCoeffs[0] = lightSpecularCoeffs[0]; myLightSpecularCoeffs[1] = lightSpecularCoeffs[1]; @@ -2089,54 +2035,48 @@ DGtal::Viewer3D::setGLLightSpecularCoefficients(const GLfloat l updateGL(); } - template -inline -void -DGtal::Viewer3D::show(){ +inline void DGtal::Viewer3D::show() +{ QGLWidget::show(); updateList(false); } +template +inline void DGtal::Viewer3D::paintGL() +{ + if ( displaysInStereo() ) + { + for ( int view = 1; view >= 0; --view ) + { + // Clears screen, set model view matrix with shifted matrix for ith buffer + preDrawStereo( view ); + postDraw(); + // Used defined method. Default is empty + if ( camera()->frame()->isManipulated() ) + fastDraw(); + else + draw(); + } + } + else + { + // Clears screen, set model view matrix... + preDraw(); + postDraw(); + // Used defined method. Default calls draw() + if ( camera()->frame()->isManipulated() ) + fastDraw(); + else + draw(); + // Add visual hints: axis, camera, grid... + } + Q_EMIT drawFinished( true ); +} template -inline -void -DGtal::Viewer3D::paintGL(){ - if (displaysInStereo()) - { - for (int view=1; view>=0; --view) - { - // Clears screen, set model view matrix with shifted matrix for ith buffer - preDrawStereo(view); - postDraw(); - // Used defined method. Default is empty - if (camera()->frame()->isManipulated()) - fastDraw(); - else - draw(); - - } - } - else - { - // Clears screen, set model view matrix... - preDraw(); - postDraw(); - // Used defined method. Default calls draw() - if (camera()->frame()->isManipulated()) - fastDraw(); - else - draw(); - // Add visual hints: axis, camera, grid... - - } - Q_EMIT drawFinished(true); -} - - -template< typename TSpace, typename TKSpace> -void DGtal::Viewer3D::updateLightCoordsFromCamera() { +void DGtal::Viewer3D::updateLightCoordsFromCamera() +{ Vec posLCam; posLCam[0] = myLightPositionRefCamera[0]; posLCam[1] = myLightPositionRefCamera[1]; @@ -2148,10 +2088,9 @@ void DGtal::Viewer3D::updateLightCoordsFromCamera() { myLightPosition[3] = 1.0f; } - - -template< typename TSpace, typename TKSpace> -void DGtal::Viewer3D::updateRelativeCameraFromLightPosition() { +template +void DGtal::Viewer3D::updateRelativeCameraFromLightPosition() +{ Vec posL; posL[0] = myLightPosition[0]; posL[1] = myLightPosition[1]; diff --git a/src/DGtal/kernel/sets/DigitalSetFromMap.ih b/src/DGtal/kernel/sets/DigitalSetFromMap.ih index 772a193f1e..bfe3583b43 100644 --- a/src/DGtal/kernel/sets/DigitalSetFromMap.ih +++ b/src/DGtal/kernel/sets/DigitalSetFromMap.ih @@ -47,10 +47,9 @@ DGtal::DigitalSetFromMap::~DigitalSetFromMap() // ------------------------------------------------------------------------ template -inline -DGtal::DigitalSetFromMap -::DigitalSetFromMap( typename DGtal::DigitalSetFromMap::Image& aImage, - const typename Image::Value& aDefaultValue ) +inline DGtal::DigitalSetFromMap::DigitalSetFromMap( +typename DGtal::DigitalSetFromMap::Image & aImage, +const typename Image::Value & aDefaultValue ) : myImgPtr( &aImage ), myFun( Functor() ), myDefault( aDefaultValue ) { } diff --git a/src/DGtal/math/linalg/SimpleMatrix.h b/src/DGtal/math/linalg/SimpleMatrix.h index 5d29512192..b3aeaea3ab 100644 --- a/src/DGtal/math/linalg/SimpleMatrix.h +++ b/src/DGtal/math/linalg/SimpleMatrix.h @@ -101,6 +101,18 @@ namespace DGtal */ SimpleMatrix(); + /** + * Constructor from initializer list. + * + * This matrix values are given row by row (top to bottom) + * from left to right. + * {a,b,c,d} = [[a b] + * [c d]] + * + * @param values the initializer list. + */ + SimpleMatrix( std::initializer_list values ); + /** * Copy constructor. * @param other the object to clone. diff --git a/src/DGtal/math/linalg/SimpleMatrix.ih b/src/DGtal/math/linalg/SimpleMatrix.ih index c051f1a37f..543a0f9366 100644 --- a/src/DGtal/math/linalg/SimpleMatrix.ih +++ b/src/DGtal/math/linalg/SimpleMatrix.ih @@ -67,6 +67,27 @@ DGtal::SimpleMatrix::SimpleMatrix() myCofactorCoefs[i*N+j] = ( (i+j) & 1 ) ? minus_one : one; } + +/** + * Constructor. + */ +template +inline +DGtal::SimpleMatrix::SimpleMatrix(std::initializer_list values) +{ + DGtal::Dimension i = 0; + for ( const T *p = values.begin(); p != values.end() && i < TM*TN; ++p, ++i ) + myValues[ i ] = *p; + for ( ; i < TM*TN; ++i ) + myValues[ i ] = NumberTraits::ZERO; + + const Component one = NumberTraits::ONE; + const Component minus_one = -NumberTraits::ONE; + // Cofactor coefs computation + for ( i = 0; i < TM; i++ ) + for ( DGtal::Dimension j = 0; j < TN; j++ ) + myCofactorCoefs[ i * N + j ] = ( ( i + j ) & 1 ) ? minus_one : one; +} //------------------------------------------------------------------------------ template diff --git a/src/DGtal/shapes/Mesh.h b/src/DGtal/shapes/Mesh.h index d730a768fa..300c406cfd 100644 --- a/src/DGtal/shapes/Mesh.h +++ b/src/DGtal/shapes/Mesh.h @@ -551,20 +551,23 @@ namespace DGtal createTubularMesh(Mesh &aMesh, const std::vector &aSkeleton, const std::vector &aVectOfRadius, const double angleStep = 0.2, const DGtal::Color &aMeshColor = DGtal::Color::White ); - - /** * Generates a surface mesh defined from a sequence of 2D - * height values (can be seen as a height map). + * height values (can be seen as a height map). * * @param[out] aMesh the mesh in which the new surface mesh will be created. - * @param[in] anValueSequence the sequence of values defining the height points. - * @param[in] lengthSequence the number of points constituing a line in the height map. - * @param[in] stepX the x grid step to define the scale of the resulting mesh. - * @param[in] stepY the y grid step to define the scale of the resulting mesh. - * @param[in] stepZ the z grid step to define the scale of the resulting mesh. + * @param[in] anValueSequence the sequence of values defining the height + *points. + * @param[in] lengthSequence the number of points constituing a line in the + *height map. + * @param[in] stepX the x grid step to define the scale of the resulting + *mesh. + * @param[in] stepY the y grid step to define the scale of the resulting + *mesh. + * @param[in] stepZ the z grid step to define the scale of the resulting + *mesh. * - * @param[in] aMeshColor the color given to the generated tube mesh. + * @param[in] aMeshColor the color given to the generated tube mesh. * **/ template diff --git a/tests/io/readers/testGenericReader.cpp b/tests/io/readers/testGenericReader.cpp index 54d86ed525..8d6db6f9f4 100644 --- a/tests/io/readers/testGenericReader.cpp +++ b/tests/io/readers/testGenericReader.cpp @@ -59,9 +59,10 @@ bool testGenericReader() typedef DGtal::ImageContainerBySTLVector Image2D; #ifdef WITH_ITK - typedef DGtal::ImageContainerBySTLVector Image3D16bits; + typedef DGtal::ImageContainerBySTLVector + Image3D16bits; #endif // WITH_ITK - + typedef DGtal::ImageContainerBySTLVector Image3D32bits; typedef DGtal::ImageContainerBySTLVector Image3D64bits; typedef DGtal::ImageContainerBySTLVector Image2D32bits; @@ -165,27 +166,41 @@ bool testGenericReader() #ifdef WITH_ITK std::string filenameImage6 = testPath + "samples/lobsterCroped16b.mhd"; - typedef DGtal::functors::Rescaling RescalFCT2; - RescalFCT2 resc2 = RescalFCT2(0, 65535,0, 255); - Image3D anImportedImage6= DGtal::GenericReader::importWithValueFunctor(filenameImage6,resc2); - DGtal::Z3i::Domain domain6 = anImportedImage6.domain(); - unsigned int size0Img6= domain6.upperBound()[0]-domain6.lowerBound()[0]+1; - unsigned int size1Img6= domain6.upperBound()[1]-domain6.lowerBound()[1]+1; - unsigned int size2Img6= domain6.upperBound()[2]-domain6.lowerBound()[2]+1; - - DGtal::trace.info()<<"mhd 16 bits 3D image read: size[0]:" << size0Img6; - DGtal::trace.info()<<"size[1]: " << size1Img6 << std::endl; - DGtal::trace.info()<<"Image value of Point (35,29, 3): " << anImportedImage6(DGtal::Z3i::Point(35,29, 3)) << " (should be" << resc2(60400) < RescalFCT2; + RescalFCT2 resc2 = RescalFCT2( 0, 65535, 0, 255 ); + Image3D anImportedImage6 = + DGtal::GenericReader::importWithValueFunctor( filenameImage6, + resc2 ); + DGtal::Z3i::Domain domain6 = anImportedImage6.domain(); + unsigned int size0Img6 = + domain6.upperBound()[ 0 ] - domain6.lowerBound()[ 0 ] + 1; + unsigned int size1Img6 = + domain6.upperBound()[ 1 ] - domain6.lowerBound()[ 1 ] + 1; + unsigned int size2Img6 = + domain6.upperBound()[ 2 ] - domain6.lowerBound()[ 2 ] + 1; + + DGtal::trace.info() << "mhd 16 bits 3D image read: size[0]:" << size0Img6; + DGtal::trace.info() << "size[1]: " << size1Img6 << std::endl; + DGtal::trace.info() << "Image value of Point (35,29, 3): " + << anImportedImage6( DGtal::Z3i::Point( 35, 29, 3 ) ) + << " (should be" << resc2( 60400 ) << std::endl; + nbok += + ( size0Img6 == 51 && size1Img6 == 91 && size2Img6 == 31 && + anImportedImage6( DGtal::Z3i::Point( 35, 29, 3 ) ) == resc2( 60400 ) ) + ? 1 + : 0; nb++; - - Image3D16bits anImportedImage7= DGtal::GenericReader::import(filenameImage6); - DGtal::trace.info()<<"Image value of Point (35,29, 3): " << anImportedImage7(DGtal::Z3i::Point(35,29, 3)) << " (should be" << 60400 << " )"<< std::endl; - nbok += (anImportedImage7(DGtal::Z3i::Point(35,29,3))==60400) ? 1 : 0; + + Image3D16bits anImportedImage7 = + DGtal::GenericReader::import( filenameImage6 ); + DGtal::trace.info() << "Image value of Point (35,29, 3): " + << anImportedImage7( DGtal::Z3i::Point( 35, 29, 3 ) ) + << " (should be" << 60400 << " )" << std::endl; + nbok += + ( anImportedImage7( DGtal::Z3i::Point( 35, 29, 3 ) ) == 60400 ) ? 1 : 0; nb++; #endif // WITH_ITK - DGtal::trace.info() << "(" << nbok << "/" << nb << ") " << std::endl; DGtal::trace.endBlock(); diff --git a/tests/io/readers/testITKReader.cpp b/tests/io/readers/testITKReader.cpp index 97dbdbd271..aac8a93375 100644 --- a/tests/io/readers/testITKReader.cpp +++ b/tests/io/readers/testITKReader.cpp @@ -34,7 +34,7 @@ #include "DGtalCatch.h" #include "DGtal/helpers/StdDefs.h" #include "DGtal/images/ImageContainerBySTLVector.h" -#include "DGtal/io/readers/ITKReader.h" +#include "DGtal/io/readers/ITKReader.h" /////////////////////////////////////////////////////////////////////////////// using namespace std; @@ -46,25 +46,28 @@ using namespace DGtal; TEST_CASE( "Testing ITKReader" ) { - //Default image selector = STLVector - typedef ImageContainerBySTLVector Image3DUC; - typedef ImageContainerBySTLVector Image3D16b; - - SECTION("Testing feature io/readers of ITKReader with 16 bits (unit16) images") - { - Image3D16b im = ITKReader::importITK(testPath + "samples/lobsterCroped16b.mhd"); - REQUIRE((im(Z3i::Point(35,29,3))==60400)); - } - - SECTION("Testing feature io/readers of ITKReader with rescaled 16 bits (unit16) images") - { - typedef DGtal::functors::Rescaling RescalFCT; - RescalFCT resc = RescalFCT(0, 65535,0, 255); - Image3DUC im = ITKReader::importITK(testPath + "samples/lobsterCroped16b.mhd", resc); - REQUIRE((im(Z3i::Point(35,29,3))==resc(60400) )); - } - + // Default image selector = STLVector + typedef ImageContainerBySTLVector Image3DUC; + typedef ImageContainerBySTLVector Image3D16b; + SECTION( + "Testing feature io/readers of ITKReader with 16 bits (unit16) images" ) + { + Image3D16b im = ITKReader::importITK( + testPath + "samples/lobsterCroped16b.mhd" ); + REQUIRE( ( im( Z3i::Point( 35, 29, 3 ) ) == 60400 ) ); + } + + SECTION( + "Testing feature io/readers of ITKReader with rescaled 16 bits (unit16) " + "images" ) + { + typedef DGtal::functors::Rescaling RescalFCT; + RescalFCT resc = RescalFCT( 0, 65535, 0, 255 ); + Image3DUC im = ITKReader::importITK( + testPath + "samples/lobsterCroped16b.mhd", resc ); + REQUIRE( ( im( Z3i::Point( 35, 29, 3 ) ) == resc( 60400 ) ) ); + } } /** @ingroup Tests **/ diff --git a/tests/io/readers/testTableReader.cpp b/tests/io/readers/testTableReader.cpp index 61b324c519..90786daf75 100644 --- a/tests/io/readers/testTableReader.cpp +++ b/tests/io/readers/testTableReader.cpp @@ -66,25 +66,27 @@ bool testNumberReader() trace.info() << "(" << nbok << "/" << nb << ") "<< std::endl; trace.endBlock(); + trace.beginBlock( "Testing reading all numbers from each lines ..." ); - - trace.beginBlock ( "Testing reading all numbers from each lines ..." ); - - std::vector > vectLineIntegers = TableReader::getLinesElementsFromFile(filename); - for(unsigned int k=0;k < vectLineIntegers.size(); k++) + std::vector> vectLineIntegers = + TableReader::getLinesElementsFromFile( filename ); + for ( unsigned int k = 0; k < vectLineIntegers.size(); k++ ) + { + for ( unsigned int l = 0; l < vectLineIntegers.at( k ).size(); l++ ) { - for(unsigned int l=0; l < vectLineIntegers.at(k).size(); l++) - { - trace.info() << " integer: "<< vectLineIntegers.at(k).at(l) << " " ; - } - trace.info() << endl; + trace.info() << " integer: " << vectLineIntegers.at( k ).at( l ) << " "; } - - nbok += (vectLineIntegers.at(0).at(0)==1 && vectLineIntegers.at(2).at(2)==9 && vectLineIntegers.at(3).at(2)==1) ? 1 : 0; + trace.info() << endl; + } + + nbok += ( vectLineIntegers.at( 0 ).at( 0 ) == 1 && + vectLineIntegers.at( 2 ).at( 2 ) == 9 && + vectLineIntegers.at( 3 ).at( 2 ) == 1 ) + ? 1 + : 0; nb++; - trace.info() << "(" << nbok << "/" << nb << ") "<< std::endl; + trace.info() << "(" << nbok << "/" << nb << ") " << std::endl; trace.endBlock(); - trace.beginBlock ( "Testing reading string ..." ); diff --git a/tests/math/linalg/testSimpleMatrix.cpp b/tests/math/linalg/testSimpleMatrix.cpp index fb991fbfb7..51b8412890 100644 --- a/tests/math/linalg/testSimpleMatrix.cpp +++ b/tests/math/linalg/testSimpleMatrix.cpp @@ -351,6 +351,36 @@ bool testInverse() return nbok == nb; } +bool testConstructor() +{ + unsigned int nbok = 0; + unsigned int nb = 0; + + trace.beginBlock( "Initilizer-list constructor test" ); + SimpleMatrix mat = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + trace.info() << mat << std::endl; + + trace.info() << "Testing values: "; + trace.info() << mat( 0, 0 ); + nbok += ( mat( 0, 0 ) == 1 ) ? 1 : 0; + nb++; + trace.info() << "(" << nbok << "/" << nb << ") "; + + trace.info() << mat( 0, 1 ); + nbok += ( mat( 0, 1 ) == 2 ) ? 1 : 0; + nb++; + trace.info() << "(" << nbok << "/" << nb << ") "; + + trace.info() << mat( 2, 2 ); + nbok += ( mat( 2, 2 ) == 9 ) ? 1 : 0; + nb++; + trace.info() << "(" << nbok << "/" << nb << ") "; + + trace.info() << std::endl; + trace.endBlock(); + return nbok == nb; +} + bool testConcepts() { typedef DGtal::SimpleMatrix Matrix; @@ -378,9 +408,9 @@ int main( int argc, char** argv ) trace.info() << " " << argv[ i ]; trace.info() << endl; - bool res = testSimpleMatrix() && testArithm() && testColRow() - && testDetCofactor() && testM1Matrix() - && testInverse() && testConcepts(); + bool res = testSimpleMatrix() && testArithm() && testColRow() && + testDetCofactor() && testM1Matrix() && testInverse() && + testConcepts() && testConstructor(); trace.emphase() << ( res ? "Passed." : "Error." ) << endl; trace.endBlock(); return res ? 0 : 1;