Ejemplo n.º 1
0
void cbbViewImage::setData(dtkAbstractData* data) {
    DTK_D(cbbViewImage);

    if (!data) 
        return;

    Images::Image* image = static_cast<Images::Image*>(data->data());

    if (!image || image->dimension()!=2)
        return;

    using namespace Images;
    using namespace Images::Pixels;

    typedef RGB<unsigned char> RGBPixel;
    typedef Polymorphic::MultiDim<2> Images2D;
    typedef Images2D::MultiType<float,Images2D::MultiType<double,Images2D::MultiType<unsigned char,Images2D::MultiType<unsigned> > > > Scalar2D;
    typedef Images2D::MultiType<RGBPixel,Scalar2D> Accepted;

    typedef RGB<double>        RGBDouble;
    Accepted::Converter<RGBDouble> convert;
    const Image2D<RGBDouble>& im = convert(image);

    const IntensityMap<RGBDouble> map(im);
    QImage qim(im.dimx(),im.dimy(),QImage::Format_RGB888);
    const Image2D<RGBDouble>::Shape& shape = im.shape();
    for (typename Image2D<RGBDouble>::Shape::const_iterator i=shape.begin();i!=shape.end();++i) {
        RGBPixel pix = map(im(i));
        qim.setPixel(i(1),i(2),(pix.red() << 8 | pix.green()) << 8 | pix.blue());
    }

    QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(qim));
    d->scene->addItem(item);
    d->view->show();
}
Ejemplo n.º 2
0
    void operator()(const Mat& mat, char* data) {
      ImageAccessor<RGBPixel> acc;
      typename Mat::const_row_iterator row = mat.row_begin();
      typename Mat::const_col_iterator col;
      char* i = data;
      for (; row != mat.row_end(); ++row) {
	for (col = row.begin(); col != row.end(); ++col) {
	  RGBPixel tmp = acc.get(col);
	  *(i++) = (unsigned char)tmp.red();
	  *(i++) = (unsigned char)tmp.green();
	  *(i++) = (unsigned char)tmp.blue();
	}
      }
    }