Exemplo n.º 1
0
void ImagPartImage
( const Matrix<T>& A, string basename="matrix", FileFormat format=PNG )
{
    DEBUG_CSE
#ifdef EL_HAVE_QT5
    typedef Base<T> Real;
    const Int m = A.Height();
    const Int n = A.Width();

    // Compute the maximum and minimum values
    double minVal=0, maxVal=0; 
    if( m != 0 && n != 0 )
    {
        minVal = maxVal = double(A.GetImagPart( 0, 0 ));
        for( Int j=0; j<n; ++j )
        {
            for( Int i=0; i<m; ++i )
            {
                minVal = Min( minVal, double(A.GetImagPart(i,j)) );
                maxVal = Max( maxVal, double(A.GetImagPart(i,j)) );
            }
        }
    }

    // TODO: Parameterize these instead
    const Int mPix = 2*m;
    const Int nPix = 2*n;
    const double mRatio = double(m) / double(mPix);
    const double nRatio = double(n) / double(nPix);
    QImage image( nPix, mPix, QImage::Format_RGB32 );
    for( Int jPix=0; jPix<nPix; ++jPix )
    {
        const Int j = nRatio*jPix;
        for( Int iPix=0; iPix<mPix; ++iPix )
        {
            const Int i = mRatio*iPix;
            QRgb color =
              SampleColorMap( double(A.GetImagPart(i,j)), minVal, maxVal );
            image.setPixel( jPix, iPix, color );
        }
    }

    SaveQImage( image, basename, format );
#else
    LogicError("Qt5 not available");
#endif // ifdef EL_HAVE_QT5
}
Exemplo n.º 2
0
void MatrixMarket( const Matrix<T>& A, string basename="matrix" )
{
    EL_DEBUG_CSE
    
    string filename = basename + "." + FileExtension(MATRIX_MARKET);
    ofstream file( filename.c_str(), std::ios::binary );
    if( !file.is_open() )
        RuntimeError("Could not open ",filename);

    // Write the header
    // ================
    {
        ostringstream os;
        os << "%%MatrixMarket matrix array ";
        if( IsComplex<T>::value )
            os << "complex "; 
        else
            os << "real ";
        os << "general\n";
        file << os.str();
    }
    
    // Write the size line
    // ===================
    const Int m = A.Height();
    const Int n = A.Width();
    file << BuildString(m," ",n,"\n");
    
    // Write the entries
    // =================
    for( Int j=0; j<n; ++j )
    {
        for( Int i=0; i<m; ++i )
        {
            ostringstream os;
            os << A.GetRealPart(i,j);
            if( IsComplex<T>::value )
                os << " " << A.GetImagPart(i,j);
            os << "\n";
            file << os.str();
        }
    }
}