Skip to content

Commit

Permalink
QgsRasterPipe
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jul 1, 2012
1 parent b34e058 commit d937dbb
Show file tree
Hide file tree
Showing 13 changed files with 464 additions and 82 deletions.
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -163,6 +163,7 @@ SET(QGIS_CORE_SRCS
raster/qgsrasterinterface.cpp
raster/qgsrasterlayer.cpp
raster/qgsrastertransparency.cpp
raster/qgsrasterpipe.cpp
raster/qgsrastershader.cpp
raster/qgsrastershaderfunction.cpp

Expand Down Expand Up @@ -391,6 +392,7 @@ SET(QGIS_CORE_HDRS
raster/qgsrasterinterface.h
raster/qgsrasterlayer.h
raster/qgsrastertransparency.h
raster/qgsrasterpipe.h
raster/qgsrastershader.h
raster/qgsrastershaderfunction.h
raster/qgsrasterviewport.h
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgsrasterdataprovider.cpp
Expand Up @@ -104,12 +104,15 @@ void * QgsRasterDataProvider::readBlock( int bandNo, QgsRectangle const & exten
return data;
}

QgsRasterDataProvider::QgsRasterDataProvider(): mDpi( -1 )
QgsRasterDataProvider::QgsRasterDataProvider()
: QgsRasterInterface( 0, QgsRasterInterface::ProviderRole )
, mDpi( -1 )
{
}

QgsRasterDataProvider::QgsRasterDataProvider( QString const & uri )
: QgsDataProvider( uri )
, QgsRasterInterface( 0, QgsRasterInterface::ProviderRole )
, mDpi( -1 )
{
}
Expand Down
20 changes: 18 additions & 2 deletions src/core/qgsrasterprojector.cpp
Expand Up @@ -26,7 +26,8 @@ QgsRasterProjector::QgsRasterProjector(
int theDestRows, int theDestCols,
double theMaxSrcXRes, double theMaxSrcYRes,
QgsRectangle theExtent )
: mSrcCRS( theSrcCRS )
: QgsRasterInterface( 0, QgsRasterInterface::ProjectorRole )
, mSrcCRS( theSrcCRS )
, mDestCRS( theDestCRS )
, mCoordinateTransform( theDestCRS, theSrcCRS )
, mDestExtent( theDestExtent )
Expand All @@ -45,7 +46,8 @@ QgsRasterProjector::QgsRasterProjector(
QgsCoordinateReferenceSystem theDestCRS,
double theMaxSrcXRes, double theMaxSrcYRes,
QgsRectangle theExtent )
: mSrcCRS( theSrcCRS )
: QgsRasterInterface( 0, QgsRasterInterface::ProjectorRole )
, mSrcCRS( theSrcCRS )
, mDestCRS( theDestCRS )
, mCoordinateTransform( theDestCRS, theSrcCRS )
, mExtent( theExtent )
Expand All @@ -54,13 +56,27 @@ QgsRasterProjector::QgsRasterProjector(
QgsDebugMsg( "Entered" );
}

QgsRasterProjector::QgsRasterProjector()
: QgsRasterInterface( 0, QgsRasterInterface::ProjectorRole )
{
QgsDebugMsg( "Entered" );
}

QgsRasterProjector::~QgsRasterProjector()
{
//delete mCoordinateTransform;
//delete pHelperTop;
//delete pHelperBottom;
}

void QgsRasterProjector::setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS )
{
mSrcCRS = theSrcCRS;
mDestCRS = theDestCRS;
mCoordinateTransform.setSourceCrs( theSrcCRS );
mCoordinateTransform.setDestCRS( theDestCRS );
}

void QgsRasterProjector::calc()
{
mCPMatrix.clear();
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsrasterprojector.h
Expand Up @@ -60,10 +60,20 @@ class QgsRasterProjector : public QgsRasterInterface
double theMaxSrcXRes, double theMaxSrcYRes,
QgsRectangle theExtent
);
QgsRasterProjector();

/** \brief The destructor */
~QgsRasterProjector();

/** \brief set source and destination CRS */
void setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS );

/** \brief set maximum source resolution */
void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes )
{
mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes;
}

/** \brief get destination point for _current_ destination position */
void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );

Expand Down Expand Up @@ -125,6 +135,9 @@ class QgsRasterProjector : public QgsRasterInterface
/** get source extent */
QgsRectangle srcExtent() { return mSrcExtent; }

/** set source extent */
void setSrcExtent( const QgsRectangle theExtent ) { mSrcExtent = theExtent; }

/** get/set source width/height */
int srcRows() { return mSrcRows; }
int srcCols() { return mSrcCols; }
Expand Down
10 changes: 6 additions & 4 deletions src/core/raster/qgsrasterinterface.cpp
Expand Up @@ -20,24 +20,26 @@

#include <QByteArray>

QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input ): mInput( input )
QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input, Role role ):
mInput( input )
, mRole( role )
{
}

QgsRasterInterface::~QgsRasterInterface()
{
}

// To give to an image preallocated memory is the only way to avoid memcpy
// To give to an image preallocated memory is the only way to avoid memcpy
// when we want to keep data but delete QImage
QImage * QgsRasterInterface::createImage ( int width, int height, QImage::Format format )
QImage * QgsRasterInterface::createImage( int width, int height, QImage::Format format )
{
// Qt has its own internal function depthForFormat(), unfortunately it is not public

QImage img( 1, 1, format );

// We ignore QImage::Format_Mono and QImage::Format_MonoLSB ( depth 1)
int size = width * height * img.bytesPerLine();
uchar * data = (uchar *) malloc ( size );
uchar * data = ( uchar * ) malloc( size );
return new QImage( data, width, height, format );
}
42 changes: 28 additions & 14 deletions src/core/raster/qgsrasterinterface.h
Expand Up @@ -15,8 +15,8 @@
* *
***************************************************************************/

#ifndef QGSRASTERFACE_H
#define QGSRASTERFACE_H
#ifndef QGSRASTERINTERFACE_H
#define QGSRASTERINTERFACE_H

#include <QObject>
#include <QImage>
Expand All @@ -26,16 +26,25 @@
/** \ingroup core
* Base class for processing modules.
*/
// TODO: inherit from QObject? QgsRasterDataProvider inherits already from QObject
// TODO: inherit from QObject? QgsDataProvider inherits already from QObject, multiple inheritance from QObject is not allowed
class CORE_EXPORT QgsRasterInterface //: public QObject
{

//Q_OBJECT

public:

// TODO: This is copy of QgsRasterDataProvider::DataType, the QgsRasterDataProvider
// should use this DataType
enum Role
{
UnknownRole = 0,
ProviderRole = 1,
RendererRole = 2,
ResamplerRole = 3,
ProjectorRole = 4
};

Role role() { return mRole; }

// This is modified copy of GDALDataType
enum DataType
{
Expand All @@ -51,11 +60,11 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
/*! Complex Int32 */ CInt32 = 9,
/*! Complex Float32 */ CFloat32 = 10,
/*! Complex Float64 */ CFloat64 = 11,
/*! Color, alpha, red, green, blue, 4 bytes the same as
QImage::Format_ARGB32 */ ARGB32 = 12,
/*! Color, alpha, red, green, blue, 4 bytes the same as
QImage::Format_ARGB32_Premultiplied */ ARGB32_Premultiplied = 13,
/*! Color, alpha, red, green, blue, 4 bytes the same as
QImage::Format_ARGB32 */ ARGB32 = 12,
/*! Color, alpha, red, green, blue, 4 bytes the same as
QImage::Format_ARGB32_Premultiplied */ ARGB32_Premultiplied = 13,

TypeCount = 14 /* maximum type # + 1 */
};

Expand Down Expand Up @@ -98,7 +107,7 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
return typeSize( dataType( bandNo ) );
}

QgsRasterInterface( QgsRasterInterface * input = 0 );
QgsRasterInterface( QgsRasterInterface * input = 0, Role role = UnknownRole );

virtual ~QgsRasterInterface();

Expand Down Expand Up @@ -128,14 +137,19 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
return 0;
}

void setInput( QgsRasterInterface* input ) { mInput = input; }
/** Set input.
* Returns true if set correctly, false if cannot use that input */
virtual bool setInput( QgsRasterInterface* input ) { mInput = input; return true; }

/** Create a new image with extraneous data, such data may be used
/** Create a new image with extraneous data, such data may be used
* after the image is destroyed. The memory is not initialized.
*/
QImage * createImage ( int width, int height, QImage::Format format );
QImage * createImage( int width, int height, QImage::Format format );

//protected:

Role mRole;

// QgsRasterInterface from used as input, data are read from it
QgsRasterInterface* mInput;

Expand Down

0 comments on commit d937dbb

Please sign in to comment.