SET(COMMON_HEADERS_H
ImageComposer.h
+ ImageComposer_MetaTypes.h
ImageComposer_ColorMaskOperator.h
ImageComposer_CropOperator.h
ImageComposer_CutOperator.h
#include "ImageComposer_ColorMaskOperator.h"
-#include "ImageComposer_Image.h"
+#include "ImageComposer_MetaTypes.h"
#include <QRectF>
#include <QRgb>
#include <QPixmap>
/**
*/
-QRectF ImageComposer_ColorMaskOperator::calcResultBoundingRect( const QRectF& theImage1Bounds,
- const QRectF& ) const
+QRectF ImageComposer_ColorMaskOperator::calcResultBoundingRect( const QVariant& theObj1,
+ const QVariant& ) const
{
- return theImage1Bounds;
+ QRectF aResRect;
+ if ( !theObj1.isNull() && theObj1.canConvert<ImageComposer_Image>() )
+ {
+ ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+ aResRect = anImage1.boundingRect();
+ }
+ return aResRect;
}
/**
*/
-void ImageComposer_ColorMaskOperator::drawResult( QPainter& thePainter,
- const ImageComposer_Image& theImage1,
- const ImageComposer_Image& ) const
+void ImageComposer_ColorMaskOperator::drawResult( QPainter& thePainter,
+ const QVariant& theObj1,
+ const QVariant& ) const
{
- QImage anImage = theImage1.convertToFormat( QImage::Format_ARGB32 );
+ if ( theObj1.isNull() || !theObj1.canConvert<ImageComposer_Image>() )
+ return;
+
+ ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+
+ QImage anImage = anImage1.convertToFormat( QImage::Format_ARGB32 );
+
int aRMin = myRefColor.red() - myRGBThreshold;
int aRMax = myRefColor.red() + myRGBThreshold;
int aGMin = myRefColor.green() - myRGBThreshold;
ImageComposer_Image aResult;
aResult = anImage;
- aResult.setTransform( theImage1.transform() );
+ aResult.setTransform( anImage1.transform() );
aResult.draw( thePainter );
}
QStringList dumpArgsToPython( QString& theArrayName ) const;
protected:
- virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds,
- const QRectF& theImage2Bounds ) const;
- virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1,
- const ImageComposer_Image& theImage2 ) const;
+ virtual QRectF calcResultBoundingRect( const QVariant& theObj1,
+ const QVariant& theObj2 ) const;
+ virtual void drawResult( QPainter& thePainter, const QVariant& theObj1,
+ const QVariant& theObj2 ) const;
virtual void storeArgs( QDataStream& theStream ) const;
virtual void restoreArgs( QDataStream& theStream );
#include "ImageComposer_CropOperator.h"
#include "ImageComposer_Image.h"
+#include "ImageComposer_MetaTypes.h"
+
#include <QPixmap>
#include <QPainter>
}
/**
- Set operator arguments
- @param theBackground the background color for result image
- @param theRect the cropping rectangle (in the global CS)
*/
-void ImageComposer_CropOperator::setArgs( const QColor& theBackground, const QRect& theRect )
+QString ImageComposer_CropOperator::name() const
{
- ImageComposer_Operator::setArgs( theBackground );
- myClipPath = QPainterPath();
- myClipPath.addRect( theRect );
+ return Type();
}
/**
- Set operator arguments
- @param theBackground the background color for result image
- @param thePath the cropping path (in the global CS)
*/
-void ImageComposer_CropOperator::setArgs( const QColor& theBackground, const QPainterPath& thePath )
+QRectF ImageComposer_CropOperator::calcResultBoundingRect( const QVariant&,
+ const QVariant& theObj2 ) const
{
- ImageComposer_Operator::setArgs( theBackground );
- myClipPath = thePath;
+ QRectF aResRect;
+ if ( !theObj2.isNull() && theObj2.canConvert<QPainterPath>() )
+ {
+ QPainterPath aCropPath = theObj2.value<QPainterPath>();
+ aResRect = aCropPath.boundingRect();
+ }
+ return aResRect;
}
/**
- Return clipping path
- @return clipping path
*/
-QPainterPath ImageComposer_CropOperator::clipPath() const
+void ImageComposer_CropOperator::drawResult( QPainter& thePainter,
+ const QVariant& theObj1,
+ const QVariant& theObj2 ) const
{
- return myClipPath;
-}
+ if ( theObj1.isNull() || !theObj1.canConvert<ImageComposer_Image>() ||
+ theObj2.isNull() || !theObj2.canConvert<QPainterPath>() )
+ return;
-/**
-*/
-QString ImageComposer_CropOperator::name() const
-{
- return Type();
-}
+ ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+ QPainterPath anImgClipPath = theObj2.value<QPainterPath>();
-/**
-*/
-QRectF ImageComposer_CropOperator::calcResultBoundingRect( const QRectF&, const QRectF& ) const
-{
- return myImgClipPath.boundingRect();
-}
+ QRectF aBounds = anImgClipPath.boundingRect();
-/**
-*/
-void ImageComposer_CropOperator::drawResult( QPainter& thePainter,
- const ImageComposer_Image& theImage1,
- const ImageComposer_Image& ) const
-{
- QRectF aBounds = myImgClipPath.boundingRect();
QTransform aTranslate;
aTranslate.translate( -aBounds.left(), -aBounds.top() );
- QPainterPath aClipPath = aTranslate.map( myImgClipPath );
+
+ QPainterPath aClipPath = aTranslate.map( anImgClipPath );
thePainter.setClipPath( aClipPath );
- theImage1.draw( thePainter );
+
+ anImage1.draw( thePainter );
//thePainter.fillPath( aClipPath, Qt::red );
}
/**
*/
-ImageComposer_Image ImageComposer_CropOperator::process( const ImageComposer_Image& theImage1,
- const ImageComposer_Image& theImage2 ) const
+ImageComposer_Image ImageComposer_CropOperator::process( const QVariant& theObj1,
+ const QVariant& theObj2 ) const
{
- QRect anImageRect( 0, 0, theImage1.width(), theImage1.height() );
- QPainterPath anImageBoundsPath;
- anImageBoundsPath.addPolygon( theImage1.transform().mapToPolygon( anImageRect ) );
+ ImageComposer_Image aResult;
+ if ( theObj1.isNull() || !theObj1.canConvert<ImageComposer_Image>() ||
+ theObj2.isNull() || !theObj2.canConvert<QPainterPath>() )
+ return aResult;
- const_cast<ImageComposer_CropOperator*>( this )->myImgClipPath =
- theImage1.transform().inverted().map( myClipPath.intersected( anImageBoundsPath ) );
+ ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+ QPainterPath aCropPath = theObj2.value<QPainterPath>();
- return ImageComposer_Operator::process( theImage1, theImage2 );
-}
+ QRect anImageRect( 0, 0, anImage1.width(), anImage1.height() );
+ QPainterPath anImageBoundsPath;
+ anImageBoundsPath.addPolygon( anImage1.transform().mapToPolygon( anImageRect ) );
-void ImageComposer_CropOperator::storeArgs( QDataStream& theStream ) const
-{
- ImageComposer_Operator::storeArgs( theStream );
- theStream << myClipPath;
-}
+ // clipping path mapped to first image's local CS
+ QVariant anImgClipPath;
+ anImgClipPath.setValue<QPainterPath>(
+ anImage1.transform().inverted().map( aCropPath.intersected( anImageBoundsPath ) ) );
-void ImageComposer_CropOperator::restoreArgs( QDataStream& theStream )
-{
- ImageComposer_Operator::restoreArgs( theStream );
- myClipPath = QPainterPath();
- theStream >> myClipPath;
+ return ImageComposer_Operator::process( theObj1, anImgClipPath );
}
ImageComposer_CropOperator();
virtual ~ImageComposer_CropOperator();
- void setArgs( const QColor& theBackground, const QRect& );
- void setArgs( const QColor& theBackground, const QPainterPath& );
-
- QPainterPath clipPath() const;
-
static QString Type() { return "crop"; }
virtual QString name() const;
- virtual ImageComposer_Image process( const ImageComposer_Image& theImage1,
- const ImageComposer_Image& theImage2 ) const;
+ virtual ImageComposer_Image process( const QVariant& theObj1,
+ const QVariant& theObj2 ) const;
protected:
- virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds,
- const QRectF& theImage2Bounds ) const;
- virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1,
- const ImageComposer_Image& theImage2 ) const;
-
- virtual void storeArgs( QDataStream& theStream ) const;
- virtual void restoreArgs( QDataStream& theStream );
+ virtual QRectF calcResultBoundingRect( const QVariant& theObj1,
+ const QVariant& theObj2 ) const;
+ virtual void drawResult( QPainter& thePainter, const QVariant& theObj1,
+ const QVariant& theObj2 ) const;
private:
friend class ImageComposerTests_TestOperators;
-
- QPainterPath myClipPath; ///< the clipping path specified initially
- QPainterPath myImgClipPath; ///< the clipping path mapped to first image's local CS
};
#endif
#include "ImageComposer_CutOperator.h"
-#include "ImageComposer_Image.h"
+#include "ImageComposer_MetaTypes.h"
#include <QString>
#include <QPixmap>
#include <QPainter>
/**
*/
-QRectF ImageComposer_CutOperator::calcResultBoundingRect( const QRectF& theImage1Bounds,
- const QRectF& ) const
+QRectF ImageComposer_CutOperator::calcResultBoundingRect( const QVariant& theObj1,
+ const QVariant& ) const
{
- return theImage1Bounds;
+ QRectF aResRect;
+ if ( !theObj1.isNull() && theObj1.canConvert<ImageComposer_Image>() )
+ {
+ ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+ aResRect = anImage1.boundingRect();
+ }
+ return aResRect;
}
/**
*/
-void ImageComposer_CutOperator::drawResult( QPainter& thePainter,
- const ImageComposer_Image& theImage1,
- const ImageComposer_Image& theImage2 ) const
+void ImageComposer_CutOperator::drawResult( QPainter& thePainter,
+ const QVariant& theObj1,
+ const QVariant& theObj2 ) const
{
- theImage1.draw( thePainter );
- theImage2.draw( thePainter );
+ if ( !theObj1.isNull() && theObj1.canConvert<ImageComposer_Image>() )
+ {
+ ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+ anImage1.draw( thePainter );
+ }
+
+ if ( !theObj2.isNull() && theObj2.canConvert<ImageComposer_Image>() )
+ {
+ ImageComposer_Image anImage2 = theObj2.value<ImageComposer_Image>();
+ anImage2.draw( thePainter );
+ }
}
virtual QString name() const;
protected:
- virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds,
- const QRectF& theImage2Bounds ) const;
- virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1,
- const ImageComposer_Image& theImage2 ) const;
+ virtual QRectF calcResultBoundingRect( const QVariant& theObj1,
+ const QVariant& theObj2 ) const;
+ virtual void drawResult( QPainter& thePainter, const QVariant& theObj1,
+ const QVariant& theObj2 ) const;
};
#endif
#include "ImageComposer_FuseOperator.h"
-#include "ImageComposer_Image.h"
+#include "ImageComposer_MetaTypes.h"
#include <QString>
#include <QPixmap>
#include <QPainter>
/**
*/
-QRectF ImageComposer_FuseOperator::calcResultBoundingRect( const QRectF& theImage1Bounds,
- const QRectF& theImage2Bounds ) const
+QRectF ImageComposer_FuseOperator::calcResultBoundingRect( const QVariant& theObj1,
+ const QVariant& theObj2 ) const
{
- return theImage1Bounds.united( theImage2Bounds );
+ QRectF aResRect;
+ if ( !theObj1.isNull() && theObj1.canConvert<ImageComposer_Image>() &&
+ !theObj2.isNull() && theObj2.canConvert<ImageComposer_Image>() )
+ {
+ ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+ ImageComposer_Image anImage2 = theObj2.value<ImageComposer_Image>();
+
+ aResRect = anImage1.boundingRect().united( anImage2.boundingRect() );
+ }
+ return aResRect;
}
/**
*/
-void ImageComposer_FuseOperator::drawResult( QPainter& thePainter,
- const ImageComposer_Image& theImage1,
- const ImageComposer_Image& theImage2 ) const
+void ImageComposer_FuseOperator::drawResult( QPainter& thePainter,
+ const QVariant& theObj1,
+ const QVariant& theObj2 ) const
{
- theImage1.draw( thePainter );
- theImage2.draw( thePainter );
+ if ( !theObj1.isNull() && theObj1.canConvert<ImageComposer_Image>() )
+ {
+ ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+ anImage1.draw( thePainter );
+ }
+
+ if ( !theObj2.isNull() && theObj2.canConvert<ImageComposer_Image>() )
+ {
+ ImageComposer_Image anImage2 = theObj2.value<ImageComposer_Image>();
+ anImage2.draw( thePainter );
+ }
}
virtual QString name() const;
protected:
- virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds,
- const QRectF& theImage2Bounds ) const;
- virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1,
- const ImageComposer_Image& theImage2 ) const;
+ virtual QRectF calcResultBoundingRect( const QVariant& theObj1,
+ const QVariant& theObj2 ) const;
+ virtual void drawResult( QPainter& thePainter, const QVariant& theObj1,
+ const QVariant& theObj2 ) const;
};
#endif
#include "ImageComposer_CropOperator.h"
#include "ImageComposer_CutOperator.h"
#include "ImageComposer_FuseOperator.h"
+#include "ImageComposer_MetaTypes.h"
+
#include <QPainter>
QColor ImageComposer_Image::myDefaultBackground = TRANSPARENT;
{
}
+/**
+ Copy constructor
+*/
+ImageComposer_Image::ImageComposer_Image( const ImageComposer_Image& theImage )
+ : QImage( theImage ),
+ myTransform( theImage.myTransform )
+{
+}
+
+/**
+ Copy constructor
+*/
+ImageComposer_Image::ImageComposer_Image( const QImage& theImage )
+ : QImage( theImage )
+{
+}
+
/**
Destructor
*/
@return the result image
*/
ImageComposer_Image ImageComposer_Image::apply( const ImageComposer_Operator& theOperator,
- const ImageComposer_Image& theImage ) const
+ const QVariant& theOtherObj ) const
{
- return theOperator.process( *this, theImage );
+ QVariant aVarData;
+ aVarData.setValue<ImageComposer_Image>( *this );
+
+ return theOperator.process( aVarData, theOtherObj );
}
/**
*/
ImageComposer_Image ImageComposer_Image::operator & ( const QRect& theRect ) const
{
- ImageComposer_CropOperator anOp;
- anOp.setArgs( myDefaultBackground, theRect );
- return apply( anOp );
+ QPainterPath aPath;
+ aPath.addRect( theRect );
+ return operator &( aPath );
}
/**
ImageComposer_Image ImageComposer_Image::operator & ( const QPainterPath& thePath ) const
{
ImageComposer_CropOperator anOp;
- anOp.setArgs( myDefaultBackground, thePath );
- return apply( anOp );
+ anOp.setArgs( myDefaultBackground );
+
+ QVariant aVarData;
+ aVarData.setValue<QPainterPath>( thePath );
+
+ return apply( anOp, aVarData );
}
/**
{
ImageComposer_CutOperator anOp;
anOp.setArgs( myDefaultBackground );
- return apply( anOp, theImage );
+
+ QVariant aVarData;
+ aVarData.setValue<ImageComposer_Image>( theImage );
+
+ return apply( anOp, aVarData );
}
/**
{
ImageComposer_FuseOperator anOp;
anOp.setArgs( myDefaultBackground );
- return apply( anOp, theImage );
+
+ QVariant aVarData;
+ aVarData.setValue<ImageComposer_Image>( theImage );
+
+ return apply( anOp, aVarData );
}
#ifndef IMAGE_COMPOSER_IMAGE_HEADER
#define IMAGE_COMPOSER_IMAGE_HEADER
-#include <QImage>
#include "ImageComposer.h"
+#include <QImage>
+
+class QVariant;
class ImageComposer_Operator;
/**
{
public:
ImageComposer_Image();
+ ImageComposer_Image( const ImageComposer_Image& theImage );
+ ImageComposer_Image( const QImage& theImage );
~ImageComposer_Image();
void draw( QPainter& thePainter ) const;
const QImage& operator = ( const QImage& theImage );
ImageComposer_Image apply( const ImageComposer_Operator& theOperator,
- const ImageComposer_Image& theImage = ImageComposer_Image() ) const;
+ const QVariant& theOtherObj ) const;
static QColor defaultBackground();
static void setDefaultBackground( const QColor& );
--- /dev/null
+
+
+#include "ImageComposer_Image.h"
+
+#include <QVariant>
+#include <QPainterPath>
+
+// Here we declare the meta types for classes which used by
+// ImageComposer operators so that it could be wrapped to QVariant
+
+Q_DECLARE_METATYPE(QPainterPath)
+Q_DECLARE_METATYPE(ImageComposer_Image)
+
#include "ImageComposer_Operator.h"
-#include "ImageComposer_Image.h"
+#include "ImageComposer_MetaTypes.h"
#include <QPixmap>
#include <QPainter>
/**
Perform the composing of images
- @param theImage1 the first image to compose
- @param theImage2 the second image to compose
+ @param theObj1 the first object to compose
+ @param theObj2 the second object to compose
@return the result image
*/
-ImageComposer_Image ImageComposer_Operator::process( const ImageComposer_Image& theImage1,
- const ImageComposer_Image& theImage2 ) const
+ImageComposer_Image ImageComposer_Operator::process( const QVariant& theObj1,
+ const QVariant& theObj2 ) const
{
- ImageComposer_Image anImage1 = theImage1;
- ImageComposer_Image anImage2 = theImage2;
+ ImageComposer_Image aResult;
+ if ( theObj1.isNull() || !theObj1.canConvert<ImageComposer_Image>() )
+ return aResult;
+
+ ImageComposer_Image anImage1 = theObj1.value<ImageComposer_Image>();
+
+ ImageComposer_Image anImage2;
+ if ( !theObj1.isNull() && theObj2.canConvert<ImageComposer_Image>() )
+ anImage2 = theObj2.value<ImageComposer_Image>();
+
QTransform aInvTransform = anImage1.transform().inverted();
anImage1.setTransform( anImage1.transform() * aInvTransform );
if( !anImage2.isNull() )
anImage2.setTransform( anImage2.transform() * aInvTransform );
- QRectF aBounds1 = anImage1.boundingRect();
- QRectF aBounds2;
- if( !anImage2.isNull() )
- aBounds2 = anImage2.boundingRect();
- QRectF aBounds = calcResultBoundingRect( aBounds1, aBounds2 );
+ QVariant anImage1Var, anImage2Var;
+ anImage1Var.setValue<ImageComposer_Image>( anImage1 );
+ anImage2Var.setValue<ImageComposer_Image>( anImage2 );
+
+ QRectF aBounds = calcResultBoundingRect( anImage1Var, !anImage2.isNull() ? anImage2Var : theObj2 );
QTransform aTranslate;
aTranslate.translate( -aBounds.left(), -aBounds.top() );
aPainter.setRenderHint( QPainter::Antialiasing, true );
aPainter.setRenderHint( QPainter::HighQualityAntialiasing, true );
- drawResult( aPainter, anImage1, anImage2 );
+ anImage1Var.setValue<ImageComposer_Image>( anImage1 );
+ anImage2Var.setValue<ImageComposer_Image>( anImage2 );
- ImageComposer_Image aResult;
- aResult = aResultImage.toImage();
- QTransform aResultTransform = theImage1.transform();
+ drawResult( aPainter, anImage1Var, !anImage2.isNull() ? anImage2Var : theObj2 );
+
+ anImage1 = theObj1.value<ImageComposer_Image>();
+
+ QTransform aResultTransform = anImage1.transform();
aResultTransform.translate( aBounds.left(), aBounds.top() );
+
+ aResult = aResultImage.toImage();
aResult.setTransform( aResultTransform );
+
return aResult;
}
#define IMAGE_COMPOSER_OPERATOR_HEADER
#include "ImageComposer.h"
+
#include <QColor>
class QString;
class QRectF;
class QPainter;
class QTransform;
+class QVariant;
class ImageComposer_Image;
const QColor TRANSPARENT( 255, 255, 255, 0 );
*/
virtual QString name() const = 0;
- virtual ImageComposer_Image process( const ImageComposer_Image& theImage1,
- const ImageComposer_Image& theImage2 ) const;
+ virtual ImageComposer_Image process( const QVariant& theObj1,
+ const QVariant& theObj2 ) const;
protected:
/**
Calculate bounding rectangle for the result image
- @param theImage1Bounds bounding rectangle of the first image
- @param theImage2Bounds bounding rectangle of the second image
+ @param theObj1 first object to calculate
+ @param theObj2 second object to calculate
@return calculated bounding rectangle
*/
- virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds,
- const QRectF& theImage2Bounds ) const = 0;
+ virtual QRectF calcResultBoundingRect( const QVariant& theObj1,
+ const QVariant& theObj2 ) const = 0;
/**
Draw result image using the given painter
@param thePainter the painter on the result image
- @param theImage1 the first image to compose
- @param theImage2 the second image to compose
+ @param theObj1 the first object to compose
+ @param theObj2 the second object to compose
*/
- virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1,
- const ImageComposer_Image& theImage2 ) const = 0;
+ virtual void drawResult( QPainter& thePainter, const QVariant& theObj1,
+ const QVariant& theObj2 ) const = 0;
virtual void storeArgs( QDataStream& theStream ) const;
virtual void restoreArgs( QDataStream& theStream );
lib_LTLIBRARIES = libImageComposer.la
-salomeinclude_HEADERS = \
-ImageComposer.h \
+salomeinclude_HEADERS = \
+ImageComposer.h \
+ImageComposer_MetaTypes.h \
ImageComposer_ColorMaskOperator.h \
-ImageComposer_CropOperator.h \
-ImageComposer_CutOperator.h \
-ImageComposer_FuseOperator.h \
-ImageComposer_Image.h \
+ImageComposer_CropOperator.h \
+ImageComposer_CutOperator.h \
+ImageComposer_FuseOperator.h \
+ImageComposer_Image.h \
ImageComposer_Operator.h
-dist_libImageComposer_la_SOURCES = \
-ImageComposer_ColorMaskOperator.cxx \
-ImageComposer_CropOperator.cxx \
-ImageComposer_CutOperator.cxx \
-ImageComposer_FuseOperator.cxx \
-ImageComposer_Image.cxx \
+dist_libImageComposer_la_SOURCES = \
+ImageComposer_ColorMaskOperator.cxx \
+ImageComposer_CropOperator.cxx \
+ImageComposer_CutOperator.cxx \
+ImageComposer_FuseOperator.cxx \
+ImageComposer_Image.cxx \
ImageComposer_Operator.cxx
libImageComposer_la_CPPFLAGS = $(QT_INCLUDES)