Loading src/TNL/Functions/MeshFunction.h +4 −3 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ class MeshFunction : typedef SharedPointer< MeshType > MeshPointer; typedef Real RealType; typedef Containers::Vector< RealType, DeviceType, IndexType > VectorType; typedef Functions::MeshFunction< Mesh, MeshEntityDimension, Real > ThisType; typedef Functions::MeshFunction< MeshType, MeshEntityDimension, RealType > ThisType; typedef Meshes::DistributedMeshes::DistributedMesh<MeshType> DistributedMeshType; typedef Meshes::DistributedMeshes::DistributedMeshSynchronizer<ThisType> DistributedMeshSynchronizerType; Loading Loading @@ -166,7 +166,8 @@ class MeshFunction : protected: DistributedMeshSynchronizerType synchronizer; //DistributedMeshSynchronizerType synchronizer; Meshes::DistributedMeshes::DistributedMeshSynchronizer< Functions::MeshFunction< MeshType, MeshEntityDimension, RealType > > synchronizer; MeshPointer meshPointer; Loading src/TNL/Images/JPEGImage.h +11 −4 Original line number Diff line number Diff line Loading @@ -42,24 +42,31 @@ class JPEGImage : public Image< Index > bool openForRead( const String& fileName ); template< typename Real, template< typename MeshReal, typename Device, typename Vector > typename Real > bool read( const RegionOfInterest< Index > roi, const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ); Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); template< typename Real, typename Device > bool openForWrite( const String& fileName, Meshes::Grid< 2, Real, Device, Index >& grid ); // TODO: Obsolete template< typename Real, typename Device, typename Vector > bool write( const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ); template< typename MeshReal, typename Device, typename Real > bool write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); void close(); ~JPEGImage(); Loading src/TNL/Images/JPEGImage_impl.h +47 −5 Original line number Diff line number Diff line Loading @@ -95,17 +95,17 @@ openForRead( const String& fileName ) } template< typename Index > template< typename Real, template< typename MeshReal, typename Device, typename Vector > typename Real > bool JPEGImage< Index >:: read( const RegionOfInterest< Index > roi, const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ) Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ) { #ifdef HAVE_JPEG_H typedef Meshes::Grid< 2, Real, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); /*** Loading Loading @@ -160,7 +160,7 @@ read( const RegionOfInterest< Index > roi, g = char_color[ 1 ] / ( Real ) 255.0; b = char_color[ 2 ] / ( Real ) 255.0; value = 0.2989 * r + 0.5870 * g + 0.1140 * b; vector.setElement( cell.getIndex(), value ); function.getData().setElement( cell.getIndex(), value ); break; default: std::cerr << "Unknown JPEG color type." << std::endl; Loading Loading @@ -262,6 +262,48 @@ write( const Meshes::Grid< 2, Real, Device, Index >& grid, #endif } template< typename Index > template< typename MeshReal, typename Device, typename Real > bool JPEGImage< Index >:: write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ) { typedef Meshes::Grid< 2, Real, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); #ifdef HAVE_JPEG_H Index i( 0 ), j; JSAMPROW row[1]; row[ 0 ] = new JSAMPLE[ grid.getDimensions().x() ]; // JSAMPLE is unsigned char while( this->cinfo.next_scanline < this->cinfo.image_height ) { for( j = 0; j < grid.getDimensions().x(); j ++ ) { cell.getCoordinates().x() = j; cell.getCoordinates().y() = grid.getDimensions().y() - 1 - i; //Index cellIndex = grid.getCellIndex( CoordinatesType( j, // grid.getDimensions().y() - 1 - i ) ); row[ 0 ][ j ] = 255 * function.getData().getElement( cell.getIndex() ); } jpeg_write_scanlines( &this->cinfo, row, 1 ); i++; } jpeg_finish_compress( &this->cinfo ); jpeg_destroy_compress( &this->cinfo ); delete[] row[ 0 ]; return true; #else return false; #endif } template< typename Index > void Loading src/TNL/Images/PGMImage.h +13 −9 Original line number Diff line number Diff line Loading @@ -19,22 +19,21 @@ namespace TNL { namespace Images { template< typename Index = int > class tnlPGMImage : public Image< Index > class PGMImage : public Image< Index > { public: typedef Index IndexType; tnlPGMImage(); PGMImage(); bool openForRead( const String& fileName ); template< typename Real, template< typename MeshReal, typename Device, typename Vector > typename Real > bool read( const RegionOfInterest< Index > roi, const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ); Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); template< typename Real, typename Device > Loading @@ -42,16 +41,21 @@ class tnlPGMImage : public Image< Index > Meshes::Grid< 2, Real, Device, Index >& grid, bool binary = true ); // TODO: obsolete template< typename Real, typename Device, typename Vector > bool write( const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ); template< typename MeshReal, typename Device, typename Real > bool write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); void close(); ~tnlPGMImage(); ~PGMImage(); protected: Loading src/TNL/Images/PGMImage_impl.h +57 −17 Original line number Diff line number Diff line /*************************************************************************** tnlPGMImage_impl.h - description PGMImage_impl.h - description ------------------- begin : Jul 20, 2015 copyright : (C) 2015 by Tomas Oberhuber Loading @@ -17,15 +17,15 @@ namespace TNL { namespace Images { template< typename Index > tnlPGMImage< Index >:: tnlPGMImage() : PGMImage< Index >:: PGMImage() : binary( false ), maxColors( 0 ), fileOpen( false ) { } template< typename Index > bool tnlPGMImage< Index >:: PGMImage< Index >:: readHeader() { char magicNumber[ 3 ]; Loading Loading @@ -60,7 +60,7 @@ readHeader() template< typename Index > bool tnlPGMImage< Index >:: PGMImage< Index >:: openForRead( const String& fileName ) { this->close(); Loading @@ -80,16 +80,16 @@ openForRead( const String& fileName ) } template< typename Index > template< typename Real, template< typename MeshReal, typename Device, typename Vector > typename Real > bool tnlPGMImage< Index >:: PGMImage< Index >:: read( const RegionOfInterest< Index > roi, const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ) Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ) { typedef Meshes::Grid< 2, Real, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); Index i, j; Loading @@ -111,7 +111,7 @@ read( const RegionOfInterest< Index > roi, cell.refresh(); //Index cellIndex = grid.getCellIndex( CoordinatesType( j - roi.getLeft(), // roi.getBottom() - 1 - i ) ); vector.setElement( cell.getIndex(), ( Real ) col / ( Real ) this->maxColors ); function.getData().setElement( cell.getIndex(), ( Real ) col / ( Real ) this->maxColors ); } } return true; Loading @@ -121,7 +121,7 @@ template< typename Index > template< typename Real, typename Device > bool tnlPGMImage< Index >:: PGMImage< Index >:: writeHeader( const Meshes::Grid< 2, Real, Device, Index >& grid, bool binary ) { Loading @@ -138,7 +138,7 @@ template< typename Index > template< typename Real, typename Device > bool tnlPGMImage< Index >:: PGMImage< Index >:: openForWrite( const String& fileName, Meshes::Grid< 2, Real, Device, Index >& grid, bool binary ) Loading @@ -165,7 +165,7 @@ template< typename Index > typename Device, typename Vector > bool tnlPGMImage< Index >:: PGMImage< Index >:: write( const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ) { Loading Loading @@ -199,9 +199,49 @@ write( const Meshes::Grid< 2, Real, Device, Index >& grid, return true; } template< typename Index > template< typename MeshReal, typename Device, typename Real > bool PGMImage< Index >:: write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ) { typedef Meshes::Grid< 2, Real, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); Index i, j; for( i = 0; i < grid.getDimensions().y(); i ++ ) { for( j = 0; j < grid.getDimensions().x(); j ++ ) { cell.getCoordinates().x() = j; cell.getCoordinates().y() = grid.getDimensions().y() - 1 - i; cell.refresh(); //Index cellIndex = grid.getCellIndex( CoordinatesType( j, // grid.getDimensions().y() - 1 - i ) ); unsigned char color = 255 * function.getData().getElement( cell.getIndex() ); if ( ! this->binary ) { int color_aux = (int)color; this->file << color_aux; this->file << ' '; } else this->file << color; } if ( ! this->binary ) this->file << '\n'; } return true; } template< typename Index > void tnlPGMImage< Index >:: PGMImage< Index >:: close() { if( this->fileOpen ) Loading @@ -210,8 +250,8 @@ close() } template< typename Index > tnlPGMImage< Index >:: ~tnlPGMImage() PGMImage< Index >:: ~PGMImage() { close(); } Loading Loading
src/TNL/Functions/MeshFunction.h +4 −3 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ class MeshFunction : typedef SharedPointer< MeshType > MeshPointer; typedef Real RealType; typedef Containers::Vector< RealType, DeviceType, IndexType > VectorType; typedef Functions::MeshFunction< Mesh, MeshEntityDimension, Real > ThisType; typedef Functions::MeshFunction< MeshType, MeshEntityDimension, RealType > ThisType; typedef Meshes::DistributedMeshes::DistributedMesh<MeshType> DistributedMeshType; typedef Meshes::DistributedMeshes::DistributedMeshSynchronizer<ThisType> DistributedMeshSynchronizerType; Loading Loading @@ -166,7 +166,8 @@ class MeshFunction : protected: DistributedMeshSynchronizerType synchronizer; //DistributedMeshSynchronizerType synchronizer; Meshes::DistributedMeshes::DistributedMeshSynchronizer< Functions::MeshFunction< MeshType, MeshEntityDimension, RealType > > synchronizer; MeshPointer meshPointer; Loading
src/TNL/Images/JPEGImage.h +11 −4 Original line number Diff line number Diff line Loading @@ -42,24 +42,31 @@ class JPEGImage : public Image< Index > bool openForRead( const String& fileName ); template< typename Real, template< typename MeshReal, typename Device, typename Vector > typename Real > bool read( const RegionOfInterest< Index > roi, const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ); Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); template< typename Real, typename Device > bool openForWrite( const String& fileName, Meshes::Grid< 2, Real, Device, Index >& grid ); // TODO: Obsolete template< typename Real, typename Device, typename Vector > bool write( const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ); template< typename MeshReal, typename Device, typename Real > bool write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); void close(); ~JPEGImage(); Loading
src/TNL/Images/JPEGImage_impl.h +47 −5 Original line number Diff line number Diff line Loading @@ -95,17 +95,17 @@ openForRead( const String& fileName ) } template< typename Index > template< typename Real, template< typename MeshReal, typename Device, typename Vector > typename Real > bool JPEGImage< Index >:: read( const RegionOfInterest< Index > roi, const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ) Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ) { #ifdef HAVE_JPEG_H typedef Meshes::Grid< 2, Real, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); /*** Loading Loading @@ -160,7 +160,7 @@ read( const RegionOfInterest< Index > roi, g = char_color[ 1 ] / ( Real ) 255.0; b = char_color[ 2 ] / ( Real ) 255.0; value = 0.2989 * r + 0.5870 * g + 0.1140 * b; vector.setElement( cell.getIndex(), value ); function.getData().setElement( cell.getIndex(), value ); break; default: std::cerr << "Unknown JPEG color type." << std::endl; Loading Loading @@ -262,6 +262,48 @@ write( const Meshes::Grid< 2, Real, Device, Index >& grid, #endif } template< typename Index > template< typename MeshReal, typename Device, typename Real > bool JPEGImage< Index >:: write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ) { typedef Meshes::Grid< 2, Real, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); #ifdef HAVE_JPEG_H Index i( 0 ), j; JSAMPROW row[1]; row[ 0 ] = new JSAMPLE[ grid.getDimensions().x() ]; // JSAMPLE is unsigned char while( this->cinfo.next_scanline < this->cinfo.image_height ) { for( j = 0; j < grid.getDimensions().x(); j ++ ) { cell.getCoordinates().x() = j; cell.getCoordinates().y() = grid.getDimensions().y() - 1 - i; //Index cellIndex = grid.getCellIndex( CoordinatesType( j, // grid.getDimensions().y() - 1 - i ) ); row[ 0 ][ j ] = 255 * function.getData().getElement( cell.getIndex() ); } jpeg_write_scanlines( &this->cinfo, row, 1 ); i++; } jpeg_finish_compress( &this->cinfo ); jpeg_destroy_compress( &this->cinfo ); delete[] row[ 0 ]; return true; #else return false; #endif } template< typename Index > void Loading
src/TNL/Images/PGMImage.h +13 −9 Original line number Diff line number Diff line Loading @@ -19,22 +19,21 @@ namespace TNL { namespace Images { template< typename Index = int > class tnlPGMImage : public Image< Index > class PGMImage : public Image< Index > { public: typedef Index IndexType; tnlPGMImage(); PGMImage(); bool openForRead( const String& fileName ); template< typename Real, template< typename MeshReal, typename Device, typename Vector > typename Real > bool read( const RegionOfInterest< Index > roi, const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ); Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); template< typename Real, typename Device > Loading @@ -42,16 +41,21 @@ class tnlPGMImage : public Image< Index > Meshes::Grid< 2, Real, Device, Index >& grid, bool binary = true ); // TODO: obsolete template< typename Real, typename Device, typename Vector > bool write( const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ); template< typename MeshReal, typename Device, typename Real > bool write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); void close(); ~tnlPGMImage(); ~PGMImage(); protected: Loading
src/TNL/Images/PGMImage_impl.h +57 −17 Original line number Diff line number Diff line /*************************************************************************** tnlPGMImage_impl.h - description PGMImage_impl.h - description ------------------- begin : Jul 20, 2015 copyright : (C) 2015 by Tomas Oberhuber Loading @@ -17,15 +17,15 @@ namespace TNL { namespace Images { template< typename Index > tnlPGMImage< Index >:: tnlPGMImage() : PGMImage< Index >:: PGMImage() : binary( false ), maxColors( 0 ), fileOpen( false ) { } template< typename Index > bool tnlPGMImage< Index >:: PGMImage< Index >:: readHeader() { char magicNumber[ 3 ]; Loading Loading @@ -60,7 +60,7 @@ readHeader() template< typename Index > bool tnlPGMImage< Index >:: PGMImage< Index >:: openForRead( const String& fileName ) { this->close(); Loading @@ -80,16 +80,16 @@ openForRead( const String& fileName ) } template< typename Index > template< typename Real, template< typename MeshReal, typename Device, typename Vector > typename Real > bool tnlPGMImage< Index >:: PGMImage< Index >:: read( const RegionOfInterest< Index > roi, const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ) Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ) { typedef Meshes::Grid< 2, Real, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); Index i, j; Loading @@ -111,7 +111,7 @@ read( const RegionOfInterest< Index > roi, cell.refresh(); //Index cellIndex = grid.getCellIndex( CoordinatesType( j - roi.getLeft(), // roi.getBottom() - 1 - i ) ); vector.setElement( cell.getIndex(), ( Real ) col / ( Real ) this->maxColors ); function.getData().setElement( cell.getIndex(), ( Real ) col / ( Real ) this->maxColors ); } } return true; Loading @@ -121,7 +121,7 @@ template< typename Index > template< typename Real, typename Device > bool tnlPGMImage< Index >:: PGMImage< Index >:: writeHeader( const Meshes::Grid< 2, Real, Device, Index >& grid, bool binary ) { Loading @@ -138,7 +138,7 @@ template< typename Index > template< typename Real, typename Device > bool tnlPGMImage< Index >:: PGMImage< Index >:: openForWrite( const String& fileName, Meshes::Grid< 2, Real, Device, Index >& grid, bool binary ) Loading @@ -165,7 +165,7 @@ template< typename Index > typename Device, typename Vector > bool tnlPGMImage< Index >:: PGMImage< Index >:: write( const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ) { Loading Loading @@ -199,9 +199,49 @@ write( const Meshes::Grid< 2, Real, Device, Index >& grid, return true; } template< typename Index > template< typename MeshReal, typename Device, typename Real > bool PGMImage< Index >:: write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ) { typedef Meshes::Grid< 2, Real, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); Index i, j; for( i = 0; i < grid.getDimensions().y(); i ++ ) { for( j = 0; j < grid.getDimensions().x(); j ++ ) { cell.getCoordinates().x() = j; cell.getCoordinates().y() = grid.getDimensions().y() - 1 - i; cell.refresh(); //Index cellIndex = grid.getCellIndex( CoordinatesType( j, // grid.getDimensions().y() - 1 - i ) ); unsigned char color = 255 * function.getData().getElement( cell.getIndex() ); if ( ! this->binary ) { int color_aux = (int)color; this->file << color_aux; this->file << ' '; } else this->file << color; } if ( ! this->binary ) this->file << '\n'; } return true; } template< typename Index > void tnlPGMImage< Index >:: PGMImage< Index >:: close() { if( this->fileOpen ) Loading @@ -210,8 +250,8 @@ close() } template< typename Index > tnlPGMImage< Index >:: ~tnlPGMImage() PGMImage< Index >:: ~PGMImage() { close(); } Loading