Loading src/core/io/tnlPGMImage.h +1 −3 Original line number Diff line number Diff line Loading @@ -36,9 +36,7 @@ class tnlPGMImage : public tnlImage< Index > bool binary; IndexType colors; IndexType maxColors; }; #include <core/io/tnlPGMImage_impl.h> Loading src/core/io/tnlPGMImage_impl.h +2 −4 Original line number Diff line number Diff line Loading @@ -24,11 +24,10 @@ template< typename Index > tnlPGMImage< Index >:: tnlPGMImage() : binary( false ), colors( 0 ) binary( false ), maxColors( 0 ) { } template< typename Index > bool tnlPGMImage< Index >:: Loading @@ -49,7 +48,6 @@ open( const tnlString& fileName ) return false; } cout << magicNumber << endl; if( strcmp( magicNumber, "P5" ) != 0 && strcmp( magicNumber, "P2" ) != 0 ) return false; Loading @@ -67,7 +65,7 @@ open( const tnlString& fileName ) else fseek( file, -1, SEEK_CUR ); fscanf( file, "%d %d\n", &this->width, &this->height ); fscanf( file, "%d\n", &this->colors ); fscanf( file, "%d\n", &this->maxColors ); return true; } Loading tools/src/tnl-image-converter.cpp +66 −27 Original line number Diff line number Diff line Loading @@ -33,38 +33,38 @@ void configSetup( tnlConfigDescription& config ) config.addEntry < bool > ( "verbose", "Set the verbosity of the program.", true ); } template< typename Image, typename Grid > bool setGrid( const Image& image, const int roiTop, const int roiBottom, const int roiLeft, const int roiRight, Grid& grid, bool verbose = false ) template< typename Index > bool resolveRoi( const tnlParameterContainer& parameters, const tnlImage< Index >* image, int& top, int& bottom, int& right, int& left ) { int left, right, bottom, top; const int roiTop = parameters.getParameter< int >( "roi-top" ); const int roiBottom = parameters.getParameter< int >( "roi-bottom" ); const int roiRight = parameters.getParameter< int >( "roi-right" ); const int roiLeft = parameters.getParameter< int >( "roi-left" ); if( roiLeft == -1 ) left = 0; else { if( roiLeft >= image.getWidth() ) if( roiLeft >= image->getWidth() ) { cerr << "ROI left column is larger than image width ( " << image.getWidth() << ")." << cerr; cerr << "ROI left column is larger than image width ( " << image->getWidth() << ")." << cerr; return false; } left = roiLeft; } if( roiRight == -1 ) right = 0; right = image->getWidth(); else { if( roiRight >= image.getWidth() ) if( roiRight >= image->getWidth() ) { cerr << "ROI right column is larger than image width ( " << image.getWidth() << ")." << cerr; cerr << "ROI right column is larger than image width ( " << image->getWidth() << ")." << cerr; return false; } right = roiRight; Loading @@ -74,25 +74,39 @@ bool setGrid( const Image& image, top = 0; else { if( roiTop >= image.getHeight() ) if( roiTop >= image->getHeight() ) { cerr << "ROI top line is larger than image height ( " << image.getHeight() << ")." << cerr; cerr << "ROI top line is larger than image height ( " << image->getHeight() << ")." << cerr; return false; } top = roiTop; } if( roiBottom == -1 ) bottom = 0; bottom = image->getHeight(); else { if( roiBottom >= image.getHeight() ) if( roiBottom >= image->getHeight() ) { cerr << "ROI bottom line is larger than image height ( " << image.getHeight() << ")." << cerr; cerr << "ROI bottom line is larger than image height ( " << image->getHeight() << ")." << cerr; return false; } bottom = roiBottom; } return true; } template< typename Index, typename Grid > bool setGrid( const tnlParameterContainer& parameters, const tnlImage< Index >* image, Grid& grid, bool verbose = false ) { int top, bottom, right, left; if( ! resolveRoi( parameters, image, top, bottom, right, left ) ) return false; grid.setDimensions( right - left, bottom - top ); typename Grid::VertexType origin, proportions; origin.x() = 0.0; Loading @@ -108,6 +122,26 @@ bool setGrid( const Image& image, return true; } template< typename Index, typename Grid > bool checkGrid( const tnlParameterContainer& parameters, const tnlImage< Index >* image, Grid& grid ) { int top, bottom, right, left; if( ! resolveRoi( parameters, image, top, bottom, right, left ) ) return false; const int width = right - left; const int height = bottom - top; if( grid.getDimensions().x() == width && grid.getDimensions().y() == height ) return true; else return false; } template< typename Image, typename Grid, typename Vector > Loading @@ -121,13 +155,11 @@ bool readImage( const Image& image, bool processImages( const tnlParameterContainer& parameters ) { const tnlList< tnlString >& inputFiles = parameters.getParameter< tnlList< tnlString > >( "input-files" ); const int roiTop = parameters.getParameter< int >( "roi-top" ); const int roiBottom = parameters.getParameter< int >( "roi-bottom" ); const int roiRight = parameters.getParameter< int >( "roi-right" ); const int roiLeft = parameters.getParameter< int >( "roi-left" ); bool verbose = parameters.getParameter< bool >( "verbose" ); tnlGrid< 2, double, tnlHost, int > grid; tnlVector< double, tnlHost, int > vector; for( int i = 0; i < inputFiles.getSize(); i++ ) { const tnlString& fileName = inputFiles[ i ]; Loading @@ -137,8 +169,15 @@ bool processImages( const tnlParameterContainer& parameters ) { cout << "PGM format detected ..."; if( i == 0 ) setGrid( pgmImage, roiTop, roiBottom, roiLeft, roiRight, grid, verbose ); cout << pgmImage.getHeight() << " " << pgmImage.getWidth() << endl; if( ! setGrid( parameters, &pgmImage, grid, verbose ) ) return false; else vector.setSize( grid.getNumberOfCells() ); else if( ! checkGrid( parameters, &pgmImage, grid ) ) return false; if( ! pgmImage.read( vector ) ) return false; } } } Loading Loading
src/core/io/tnlPGMImage.h +1 −3 Original line number Diff line number Diff line Loading @@ -36,9 +36,7 @@ class tnlPGMImage : public tnlImage< Index > bool binary; IndexType colors; IndexType maxColors; }; #include <core/io/tnlPGMImage_impl.h> Loading
src/core/io/tnlPGMImage_impl.h +2 −4 Original line number Diff line number Diff line Loading @@ -24,11 +24,10 @@ template< typename Index > tnlPGMImage< Index >:: tnlPGMImage() : binary( false ), colors( 0 ) binary( false ), maxColors( 0 ) { } template< typename Index > bool tnlPGMImage< Index >:: Loading @@ -49,7 +48,6 @@ open( const tnlString& fileName ) return false; } cout << magicNumber << endl; if( strcmp( magicNumber, "P5" ) != 0 && strcmp( magicNumber, "P2" ) != 0 ) return false; Loading @@ -67,7 +65,7 @@ open( const tnlString& fileName ) else fseek( file, -1, SEEK_CUR ); fscanf( file, "%d %d\n", &this->width, &this->height ); fscanf( file, "%d\n", &this->colors ); fscanf( file, "%d\n", &this->maxColors ); return true; } Loading
tools/src/tnl-image-converter.cpp +66 −27 Original line number Diff line number Diff line Loading @@ -33,38 +33,38 @@ void configSetup( tnlConfigDescription& config ) config.addEntry < bool > ( "verbose", "Set the verbosity of the program.", true ); } template< typename Image, typename Grid > bool setGrid( const Image& image, const int roiTop, const int roiBottom, const int roiLeft, const int roiRight, Grid& grid, bool verbose = false ) template< typename Index > bool resolveRoi( const tnlParameterContainer& parameters, const tnlImage< Index >* image, int& top, int& bottom, int& right, int& left ) { int left, right, bottom, top; const int roiTop = parameters.getParameter< int >( "roi-top" ); const int roiBottom = parameters.getParameter< int >( "roi-bottom" ); const int roiRight = parameters.getParameter< int >( "roi-right" ); const int roiLeft = parameters.getParameter< int >( "roi-left" ); if( roiLeft == -1 ) left = 0; else { if( roiLeft >= image.getWidth() ) if( roiLeft >= image->getWidth() ) { cerr << "ROI left column is larger than image width ( " << image.getWidth() << ")." << cerr; cerr << "ROI left column is larger than image width ( " << image->getWidth() << ")." << cerr; return false; } left = roiLeft; } if( roiRight == -1 ) right = 0; right = image->getWidth(); else { if( roiRight >= image.getWidth() ) if( roiRight >= image->getWidth() ) { cerr << "ROI right column is larger than image width ( " << image.getWidth() << ")." << cerr; cerr << "ROI right column is larger than image width ( " << image->getWidth() << ")." << cerr; return false; } right = roiRight; Loading @@ -74,25 +74,39 @@ bool setGrid( const Image& image, top = 0; else { if( roiTop >= image.getHeight() ) if( roiTop >= image->getHeight() ) { cerr << "ROI top line is larger than image height ( " << image.getHeight() << ")." << cerr; cerr << "ROI top line is larger than image height ( " << image->getHeight() << ")." << cerr; return false; } top = roiTop; } if( roiBottom == -1 ) bottom = 0; bottom = image->getHeight(); else { if( roiBottom >= image.getHeight() ) if( roiBottom >= image->getHeight() ) { cerr << "ROI bottom line is larger than image height ( " << image.getHeight() << ")." << cerr; cerr << "ROI bottom line is larger than image height ( " << image->getHeight() << ")." << cerr; return false; } bottom = roiBottom; } return true; } template< typename Index, typename Grid > bool setGrid( const tnlParameterContainer& parameters, const tnlImage< Index >* image, Grid& grid, bool verbose = false ) { int top, bottom, right, left; if( ! resolveRoi( parameters, image, top, bottom, right, left ) ) return false; grid.setDimensions( right - left, bottom - top ); typename Grid::VertexType origin, proportions; origin.x() = 0.0; Loading @@ -108,6 +122,26 @@ bool setGrid( const Image& image, return true; } template< typename Index, typename Grid > bool checkGrid( const tnlParameterContainer& parameters, const tnlImage< Index >* image, Grid& grid ) { int top, bottom, right, left; if( ! resolveRoi( parameters, image, top, bottom, right, left ) ) return false; const int width = right - left; const int height = bottom - top; if( grid.getDimensions().x() == width && grid.getDimensions().y() == height ) return true; else return false; } template< typename Image, typename Grid, typename Vector > Loading @@ -121,13 +155,11 @@ bool readImage( const Image& image, bool processImages( const tnlParameterContainer& parameters ) { const tnlList< tnlString >& inputFiles = parameters.getParameter< tnlList< tnlString > >( "input-files" ); const int roiTop = parameters.getParameter< int >( "roi-top" ); const int roiBottom = parameters.getParameter< int >( "roi-bottom" ); const int roiRight = parameters.getParameter< int >( "roi-right" ); const int roiLeft = parameters.getParameter< int >( "roi-left" ); bool verbose = parameters.getParameter< bool >( "verbose" ); tnlGrid< 2, double, tnlHost, int > grid; tnlVector< double, tnlHost, int > vector; for( int i = 0; i < inputFiles.getSize(); i++ ) { const tnlString& fileName = inputFiles[ i ]; Loading @@ -137,8 +169,15 @@ bool processImages( const tnlParameterContainer& parameters ) { cout << "PGM format detected ..."; if( i == 0 ) setGrid( pgmImage, roiTop, roiBottom, roiLeft, roiRight, grid, verbose ); cout << pgmImage.getHeight() << " " << pgmImage.getWidth() << endl; if( ! setGrid( parameters, &pgmImage, grid, verbose ) ) return false; else vector.setSize( grid.getNumberOfCells() ); else if( ! checkGrid( parameters, &pgmImage, grid ) ) return false; if( ! pgmImage.read( vector ) ) return false; } } } Loading