예제 #1
0
void ProcessorList::mouseDrag(const MouseEvent& e)
{

	if (e.getMouseDownX() < getWidth() && !(isDragging))
	{

		ProcessorListItem* listItem = getListItemForYPos(e.getMouseDownY());

		if (listItem != 0)
		{

			if (!listItem->hasSubItems())
			{
				isDragging = true;

				String b = listItem->getName();

				const String dragDescription = b;

				//std::cout << dragDescription << std::endl;

				if (dragDescription.isNotEmpty())
				{
					DragAndDropContainer* const dragContainer
						= DragAndDropContainer::findParentDragContainerFor(this);

					if (dragContainer != 0)
					{
						//pos.setSize (pos.getWidth(), 10);

						Image dragImage(Image::ARGB, 100, 15, true);

						Graphics g(dragImage);
						g.setColour(findColour(listItem->colorId));
						g.fillAll();
						g.setColour(Colours::white);
						g.setFont(14);
						g.drawSingleLineText(listItem->getName(),10,12);//,75,15,Justification::centredRight,true);

						dragImage.multiplyAllAlphas(0.6f);

						Point<int> imageOffset(20,10);

						//See ProcessorGraph::createProcesorFromDescription for description info
						Array<var> dragData;
						dragData.add(true);
						dragData.add(dragDescription);
						dragData.add(listItem->processorType);
						dragData.add(listItem->processorId);
						dragData.add(listItem->getParentName());

						dragContainer->startDragging(dragData, this,
								dragImage, true, &imageOffset);
					}
				}
			}
		}
	}

}
예제 #2
0
void QgsGlowEffect::draw( QgsRenderContext &context )
{
  if ( !source() || !enabled() || !context.painter() )
    return;

  QImage im = sourceAsImage( context )->copy();

  QgsColorRamp* ramp = nullptr;
  if ( mColorType == ColorRamp && mRamp )
  {
    ramp = mRamp;
  }
  else
  {
    //create a temporary ramp
    QColor transparentColor = mColor;
    transparentColor.setAlpha( 0 );
    ramp = new QgsGradientColorRamp( mColor, transparentColor );
  }

  QgsImageOperation::DistanceTransformProperties dtProps;
  dtProps.spread = mSpread * QgsSymbolLayerUtils::pixelSizeScaleFactor( context, mSpreadUnit, mSpreadMapUnitScale );
  dtProps.useMaxDistance = false;
  dtProps.shadeExterior = shadeExterior();
  dtProps.ramp = ramp;
  QgsImageOperation::distanceTransform( im, dtProps );

  if ( mBlurLevel > 0 )
  {
    QgsImageOperation::stackBlur( im, mBlurLevel );
  }

  QgsImageOperation::multiplyOpacity( im, 1.0 - mTransparency );

  if ( !shadeExterior() )
  {
    //only keep interior portion
    QPainter p( &im );
    p.setRenderHint( QPainter::Antialiasing );
    p.setCompositionMode( QPainter::CompositionMode_DestinationIn );
    p.drawImage( 0, 0, *sourceAsImage( context ) );
    p.end();
  }

  QPainter* painter = context.painter();
  painter->save();
  painter->setCompositionMode( mBlendMode );
  painter->drawImage( imageOffset( context ), im );
  painter->restore();

  if ( !mRamp )
  {
    //delete temporary ramp
    delete ramp;
  }
}
예제 #3
0
void QgsBlurEffect::drawBlurredImage( QgsRenderContext &context, QImage &image )
{
  //transparency
  QgsImageOperation::multiplyOpacity( image, 1.0 - mTransparency );

  QPainter *painter = context.painter();
  painter->save();
  painter->setCompositionMode( mBlendMode );
  painter->drawImage( imageOffset( context ), image );
  painter->restore();
}
예제 #4
0
void ProcessorList::mouseDragInCanvas(const MouseEvent& e)
{

    if (e.getMouseDownX() < getWidth()-getScrollBarWidth() && !(isDragging))
    {

        ProcessorListItem* fli = getListItemForYPos(e.getMouseDownY());

        if (fli != 0)
        {

            if (!fli->hasSubItems())
            {
                isDragging = true;

                String b = fli->getParentName();
                b += "/";
                b += fli->getName();

                const String dragDescription = b;

                //std::cout << dragDescription << std::endl;

                if (dragDescription.isNotEmpty())
                {
                    DragAndDropContainer* const dragContainer
                    = DragAndDropContainer::findParentDragContainerFor(this);

                    if (dragContainer != 0)
                    {
                        //pos.setSize (pos.getWidth(), 10);

                        Image dragImage(Image::ARGB, 100, 15, true);

                        Graphics g(dragImage);
                        g.setColour(findColour(fli->colorId));
                        g.fillAll();
                        g.setColour(Colours::white);
                        g.setFont(14);
                        g.drawSingleLineText(fli->getName(),10,12);//,75,15,Justification::centredRight,true);

                        dragImage.multiplyAllAlphas(0.6f);

                        Point<int> imageOffset(20,10);
                        dragContainer->startDragging(dragDescription, this,
                                                     dragImage, true, &imageOffset);
                    }
                }
            }
        }
    }

}
예제 #5
0
void QgsDrawSourceEffect::draw( QgsRenderContext &context )
{
  if ( !enabled() || !context.painter() )
    return;

  QPainter *painter = context.painter();

  if ( mBlendMode == QPainter::CompositionMode_SourceOver && qgsDoubleNear( mTransparency, 0.0 ) )
  {
    //just draw unmodified source
    drawSource( *painter );
  }
  else
  {
    //rasterize source and apply modifications
    QImage image = sourceAsImage( context )->copy();
    QgsImageOperation::multiplyOpacity( image, 1.0 - mTransparency );
    painter->save();
    painter->setCompositionMode( mBlendMode );
    painter->drawImage( imageOffset( context ), image );
    painter->restore();
  }
}
예제 #6
0
void QgsColorEffect::draw( QgsRenderContext &context )
{
  if ( !source() || !enabled() || !context.painter() )
    return;

  QPainter* painter = context.painter();

  //rasterise source and apply modifications
  QImage image = sourceAsImage( context )->copy();

  QgsImageOperation::adjustBrightnessContrast( image, mBrightness, mContrast / 100.0 + 1 );
  if ( mGrayscaleMode != QgsImageOperation::GrayscaleOff )
  {
    QgsImageOperation::convertToGrayscale( image, static_cast< QgsImageOperation::GrayscaleMode >( mGrayscaleMode ) );
  }
  QgsImageOperation::adjustHueSaturation( image, mSaturation, mColorizeOn ? mColorizeColor : QColor(), mColorizeStrength / 100.0 );

  QgsImageOperation::multiplyOpacity( image, 1.0 - mTransparency );
  painter->save();
  painter->setCompositionMode( mBlendMode );
  painter->drawImage( imageOffset( context ), image );
  painter->restore();
}
예제 #7
0
void SvgImageView::adjustItemPos()
{
    mSvgItem->setPos(imageOffset() - scrollPos());
}
    void ItkReader::ReadImageDirect(DataContainer& data) {
        typedef itk::ImageIOBase::IOComponentType ScalarPixelType;

        itk::ImageIOBase::Pointer imageIO =
            itk::ImageIOFactory::CreateImageIO(p_url.getValue().c_str(), itk::ImageIOFactory::ReadMode);

        if (imageIO.IsNotNull())
        {
            WeaklyTypedPointer wtp;

            imageIO->SetFileName(p_url.getValue());
            imageIO->ReadImageInformation();

            const ScalarPixelType pixelType = imageIO->GetComponentType();
            const size_t numDimensions = imageIO->GetNumberOfDimensions();

            LDEBUG("Reading Image with Reader " << imageIO->GetNameOfClass());
            LDEBUG("Pixel Type is " << imageIO->GetComponentTypeAsString(pixelType));
            LDEBUG("numDimensions: " << numDimensions);

            if (numDimensions > 3) {
                LERROR("Error: Dimensions higher than 3 not supported!");
                return;
            }

            itk::ImageIORegion ioRegion(numDimensions);
            itk::ImageIORegion::IndexType ioStart = ioRegion.GetIndex();
            itk::ImageIORegion::SizeType ioSize = ioRegion.GetSize();

            cgt::vec3 imageOffset(0.f);
            cgt::vec3 voxelSize(1.f);
            cgt::ivec3 size_i(1);

            //we assured above that numDimensions is < 3
            for (int i = 0; i < static_cast<int>(numDimensions); i++) {
                size_i[i] = imageIO->GetDimensions(i);
                imageOffset[i] = imageIO->GetOrigin(i);
                voxelSize[i] = imageIO->GetSpacing(i);
                ioStart[i] = 0;
                ioSize[i] = size_i[i];
            }

            cgt::svec3 size(size_i);
            size_t dimensionality = (size_i[2] == 1) ? ((size_i[1] == 1) ? 1 : 2) : 3;

            LDEBUG("Image Size is " << size);
            LDEBUG("Voxel Size is " << voxelSize);
            LDEBUG("Image Offset is " << imageOffset);
            LDEBUG("component size: " << imageIO->GetComponentSize());
            LDEBUG("components: " << imageIO->GetNumberOfComponents());
            LDEBUG("pixel type (string): " << imageIO->GetPixelTypeAsString(imageIO->GetPixelType())); // 'vector'
            LDEBUG("pixel type: " << imageIO->GetPixelType()); // '5'

            switch (pixelType) {
            case itk::ImageIOBase::CHAR:
                wtp._baseType = WeaklyTypedPointer::INT8; break;
            case itk::ImageIOBase::UCHAR:
                wtp._baseType = WeaklyTypedPointer::UINT8; break;
            case itk::ImageIOBase::SHORT:
                wtp._baseType = WeaklyTypedPointer::INT16; break;
            case itk::ImageIOBase::USHORT:
                wtp._baseType = WeaklyTypedPointer::UINT16; break;
            case itk::ImageIOBase::INT:
                wtp._baseType = WeaklyTypedPointer::INT32; break;
            case itk::ImageIOBase::UINT:
                wtp._baseType = WeaklyTypedPointer::UINT32; break;
            case itk::ImageIOBase::DOUBLE:
                LWARNING("Pixel Type is DOUBLE. Conversion to float may result in loss of precision!");
            case itk::ImageIOBase::FLOAT:
                wtp._baseType = WeaklyTypedPointer::FLOAT; break;


            default:
                LERROR("Error while loading ITK image: unsupported type: " << pixelType);
                return;
            }

            wtp._numChannels = imageIO->GetNumberOfComponents();

            //Setup the image region to read
            ioRegion.SetIndex(ioStart);
            ioRegion.SetSize(ioSize);
            imageIO->SetIORegion(ioRegion);

            if (pixelType != itk::ImageIOBase::DOUBLE) {
                //Finally, allocate buffer and read the image data
                wtp._pointer = new uint8_t[imageIO->GetImageSizeInBytes()];
                imageIO->Read(wtp._pointer);
            }
            else {
                //convert float volume to double volume
                double * inputBuf = new double[imageIO->GetImageSizeInComponents()];
                wtp._pointer = new uint8_t[imageIO->GetImageSizeInComponents() * sizeof(float)];
                imageIO->Read(inputBuf);

                double * dptr = inputBuf;
                float * fptr = static_cast<float*>(wtp._pointer);
                for (int i = 0, s = imageIO->GetImageSizeInComponents(); i < s; ++i) {
                    *fptr = *dptr;
                    fptr++;
                    dptr++;
                }
                delete[] inputBuf;
            }

            ImageData* image = new ImageData(dimensionality, size, wtp._numChannels);
            ImageRepresentationLocal::create(image, wtp);

            image->setMappingInformation(ImageMappingInformation(size, imageOffset/* + p_imageOffset.getValue()*/, voxelSize /** p_voxelSize.getValue()*/));
            data.addData(p_targetImageID.getValue(), image);
        }
        else {
            LWARNING("Unable to create ImageIO Instance; No suitable reader found!");
        }
    }
    void ItkReader::ReadImageSeries(DataContainer& data) {
        typedef itk::ImageIOBase::IOComponentType ScalarPixelType;

        std::vector<std::string> imageFileNames = GetImageFileNames();

        if (!imageFileNames.size())
            return;

        itk::ImageIOBase::Pointer imageIO =
            itk::ImageIOFactory::CreateImageIO(imageFileNames[0].c_str(), itk::ImageIOFactory::ReadMode);

        const int numSlices = imageFileNames.size();

        if (imageIO.IsNotNull())
        {
            WeaklyTypedPointer wtp;

            imageIO->SetFileName(imageFileNames[0]);
            imageIO->ReadImageInformation();

            const ScalarPixelType pixelType = imageIO->GetComponentType();
            const size_t numDimensions = imageIO->GetNumberOfDimensions();

            LDEBUG("Reading Image with Reader " << imageIO->GetNameOfClass());
            LDEBUG("Pixel Type is " << imageIO->GetComponentTypeAsString(pixelType));
            LDEBUG("numDimensions: " << numDimensions);

            if (numDimensions > 3) {
                LERROR("Error: Dimensions higher than 3 not supported!");
                return;
            }

            itk::ImageIORegion ioRegion(numDimensions);
            itk::ImageIORegion::IndexType ioStart = ioRegion.GetIndex();
            itk::ImageIORegion::SizeType ioSize = ioRegion.GetSize();

            cgt::vec3 imageOffset(0.f);
            cgt::vec3 voxelSize(1.f);
            cgt::ivec3 size_i(1);

            //we assured above that numDimensions is < 3
            for (int i = 0; i < static_cast<int>(numDimensions); i++) {
                size_i[i] = imageIO->GetDimensions(i);
                imageOffset[i] = imageIO->GetOrigin(i);
                voxelSize[i] = imageIO->GetSpacing(i);
                ioStart[i] = 0;
                ioSize[i] = size_i[i];
            }

            cgt::svec3 size(size_i);
            size_t dimensionality = (size_i[2] == 1) ? ((size_i[1] == 1) ? 1 : 2) : 3;
            if (dimensionality > 2) {
                LERROR("Error: Cannot load image series with more than two dimensions!");
                return;
            }

            LDEBUG("Image Size is " << size);
            LDEBUG("Voxel Size is " << voxelSize);
            LDEBUG("Image Offset is " << imageOffset);
            LDEBUG("component size: " << imageIO->GetComponentSize());
            LDEBUG("components: " << imageIO->GetNumberOfComponents());
            LDEBUG("pixel type (string): " << imageIO->GetPixelTypeAsString(imageIO->GetPixelType()));
            LDEBUG("pixel type: " << imageIO->GetPixelType());

            switch (pixelType) {
            case itk::ImageIOBase::CHAR:
                wtp._baseType = WeaklyTypedPointer::INT8; break;
            case itk::ImageIOBase::UCHAR:
                wtp._baseType = WeaklyTypedPointer::UINT8; break;
            case itk::ImageIOBase::SHORT:
                wtp._baseType = WeaklyTypedPointer::INT16; break;
            case itk::ImageIOBase::USHORT:
                wtp._baseType = WeaklyTypedPointer::UINT16; break;
            case itk::ImageIOBase::INT:
                wtp._baseType = WeaklyTypedPointer::INT32; break;
            case itk::ImageIOBase::UINT:
                wtp._baseType = WeaklyTypedPointer::UINT32; break;
            case itk::ImageIOBase::DOUBLE:
                LWARNING("Pixel Type is DOUBLE. Conversion to float may result in loss of precision!");
            case itk::ImageIOBase::FLOAT:
                wtp._baseType = WeaklyTypedPointer::FLOAT; break;


            default:
                LERROR("Error while loading ITK image: unsupported type: " << pixelType);
                return;
            }

            wtp._numChannels = imageIO->GetNumberOfComponents();

            //Setup the image region to read
            ioRegion.SetIndex(ioStart);
            ioRegion.SetSize(ioSize);
            imageIO->SetIORegion(ioRegion);

            //allocate a temporary buffer if necessary
            double* inputBuf = (pixelType == itk::ImageIOBase::DOUBLE) ? new double[imageIO->GetImageSizeInComponents()] : nullptr;
            size_t sliceSize = (pixelType == itk::ImageIOBase::DOUBLE) ? imageIO->GetImageSizeInComponents() * sizeof(float) : imageIO->GetImageSizeInBytes();
            wtp._pointer = new uint8_t[numSlices * sliceSize];
            for (int idx = 0; idx < numSlices; ++idx) {
                itk::ImageIOBase::Pointer fileIO = imageIO;
                    //itk::ImageIOFactory::CreateImageIO(imageFileNames[idx].c_str(), itk::ImageIOFactory::ReadMode);
                fileIO->SetFileName(imageFileNames[idx]);
                fileIO->ReadImageInformation();
                fileIO->SetIORegion(ioRegion);

                size_t currentSliceSize = (pixelType == itk::ImageIOBase::DOUBLE) ? imageIO->GetImageSizeInComponents() * sizeof(float) : fileIO->GetImageSizeInBytes();
                if (currentSliceSize != sliceSize) {
                    LERROR("Image " << imageFileNames[idx] << " has different dimensionality or data type!");
                    delete static_cast<uint8_t*>(wtp._pointer);
                    delete inputBuf;
                    wtp._pointer = nullptr;
                    return;
                }

                uint8_t* sliceBuffer = static_cast<uint8_t*>(wtp._pointer) + idx * sliceSize;

                if (pixelType != itk::ImageIOBase::DOUBLE) {
                    // directly read slice into buffer
                    fileIO->Read(sliceBuffer);
                }
                else {
                    //convert float volume to double volume
                    fileIO->Read(inputBuf);

                    double* dptr = inputBuf;
                    float* fptr = reinterpret_cast<float*>(sliceBuffer);
                    for (int i = 0, s = fileIO->GetImageSizeInComponents(); i < s; ++i) {
                        *fptr = static_cast<float>(*dptr);
                        fptr++;
                        dptr++;
                    }
                }
            }
            delete[] inputBuf;

            size[2] = numSlices;
            //series adds one dimension
            ImageData* image = new ImageData(dimensionality+1, size, wtp._numChannels);
            ImageRepresentationLocal::create(image, wtp);

            image->setMappingInformation(ImageMappingInformation(size, imageOffset/* + p_imageOffset.getValue()*/, voxelSize /** p_voxelSize.getValue()*/));
            data.addData(p_targetImageID.getValue(), image);
        }
        else {
            LWARNING("Unable to create ImageIO Instance; No suitable reader found!");
        }
    }