Skip to content
Snippets Groups Projects
Commit 50191569 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Fixed MatrixWriter class

parent 5b487573
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@
#pragma once
#include <ostream>
#include <iostream>
namespace TNL {
namespace Matrices {
......@@ -23,26 +24,27 @@ class MatrixWriter
typedef typename Matrix::IndexType IndexType;
typedef typename Matrix::RealType RealType;
static bool writeToGnuplot( std::ostream str,
static bool writeToGnuplot( std::ostream& str,
const Matrix& matrix,
bool verbose = false );
static bool writeToEps( std::ostream str,
static bool writeToEps( std::ostream& str,
const Matrix& matrix,
bool verbose = false );
protected:
static bool writeEpsHeader( std::ostream str,
static bool writeEpsHeader( std::ostream& str,
const Matrix& matrix,
const int elementSize );
static bool writeEpsBody( std::ostream str,
static bool writeEpsBody( std::ostream& str,
const Matrix& matrix,
const int elementSize );
const int elementSize,
bool verbose );
};
} // namespace Matrices
} // namespace TNL
#include <TNL/Matrices/MatrixWriter_impl.h>
......@@ -10,21 +10,23 @@
#pragma once
#include <TNL/Matrices/MatrixWriter.h>
namespace TNL {
namespace Matrices {
template< typename Matrix >
bool MatrixWriter< Matrix >::writeToGnuplot( std::ostream str,
const Matrix& matrix,
bool verbose )
bool MatrixWriter< Matrix >::writeToGnuplot( std::ostream& str,
const Matrix& matrix,
bool verbose )
{
for( IndexType row = 0; row < matrix.getRows(); row ++ )
{
for( IndexType column = 0; column < matrix.getColumns(); column ++ )
{
RealType elementValue = maytrix.getElement( row, column );
RealType elementValue = matrix.getElement( row, column );
if( elementValue != ( RealType ) 0.0 )
str << column << " " << getSize() - row << " " << elementValue << std::endl;
str << column << " " << row << " " << elementValue << std::endl;
}
if( verbose )
std::cout << "Drawing the row " << row << " \r" << std::flush;
......@@ -35,9 +37,9 @@ bool MatrixWriter< Matrix >::writeToGnuplot( std::ostream str,
}
template< typename Matrix >
bool MatrixWriter< Matrix >::writeToEps( std::ostream str,
const Matrix& matrix,
bool verbose )
bool MatrixWriter< Matrix >::writeToEps( std::ostream& str,
const Matrix& matrix,
bool verbose )
{
const int elementSize = 10;
if( ! writeEpsHeader( str, matrix, elementSize ) )
......@@ -54,9 +56,9 @@ bool MatrixWriter< Matrix >::writeToEps( std::ostream str,
}
template< typename Matrix >
bool MatrixWriter< Matrix >::writeEpsHeader( std::ostream str,
const Marix& matrix,
const int elementSize )
bool MatrixWriter< Matrix >::writeEpsHeader( std::ostream& str,
const Matrix& matrix,
const int elementSize )
{
const double scale = elementSize * max( matrix.getRows(), matrix.getColumns() );
str << "%!PS-Adobe-2.0 EPSF-2.0" << std::endl;
......@@ -69,14 +71,15 @@ bool MatrixWriter< Matrix >::writeEpsHeader( std::ostream str,
}
template< typename Matrix >
bool MatrixWriter< Matrix >::writeEpsBody( std::ostream str,
const Marix& matrix,
const int elementSize )
bool MatrixWriter< Matrix >::writeEpsBody( std::ostream& str,
const Matrix& matrix,
const int elementSize,
bool verbose )
{
IndexType lastRow( 0 ), lastColumn( 0 );
for( IndexType row = 0; row < getSize(); row ++ )
for( IndexType row = 0; row < matrix.getRows(); row ++ )
{
for( IndexType column = 0; column < getSize(); column ++ )
for( IndexType column = 0; column < matrix.getColumns(); column ++ )
{
RealType elementValue = getElement( row, column );
if( elementValue != ( RealType ) 0.0 )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment