void TwoLineDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, QtEvent* event) const { painter->save(); QRect fullRegion(option.rect); if ( option.state & QStyle::State_Selected ) { painter->fillRect(fullRegion, option.palette.highlight()); painter->setPen(option.palette.highlightedText().color()); } else { QColor nameColor = event->data(Qt::TextColorRole).value<QColor>(); painter->setPen(QPen(nameColor)); } QFontMetrics nameMetrics(common_.nameFont); painter->setFont(common_.nameFont); int extraFontWidth = nameMetrics.width("H"); int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2; QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0)); int nameHeight = nameMetrics.height() + common_.verticalMargin; QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); DelegateCommons::drawElidedText(painter, nameRegion, event->data(firstRole_).toString()); painter->setFont(common_.detailFont); painter->setPen(QPen(secondLineColor)); QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); DelegateCommons::drawElidedText(painter, detailRegion, event->data(secondRole_).toString()); painter->restore(); }
PriorityViewerWidget<TPriority, TBoundaryStatusMapType>::PriorityViewerWidget(TPriority* const priorityFunction, const itk::Size<2>& imageSize, TBoundaryStatusMapType* boundaryStatusMap) : PriorityFunction(priorityFunction), ImageSize(imageSize), PreviouslyDisplayed(false), BoundaryStatusMap(boundaryStatusMap) { this->setupUi(this); this->PriorityImage = PriorityImageType::New(); itk::ImageRegion<2> fullRegion(ITKHelpers::CornerRegion(this->ImageSize)); this->PriorityImage->SetRegions(fullRegion); this->PriorityImage->Allocate(); this->InteractorStyle = vtkSmartPointer<InteractorStyleImageWithDrag>::New(); this->Renderer = vtkSmartPointer<vtkRenderer>::New(); this->qvtkWidget->GetRenderWindow()->AddRenderer(this->Renderer); this->Renderer->AddViewProp(this->ImageLayer.ImageSlice); // Without this here (and then setting it to true later after it is populated), // you will get "This data object does not contain the requested extent this->ImageLayer.ImageSlice->VisibilityOff(); this->InteractorStyle->SetCurrentRenderer(this->Renderer); this->qvtkWidget->GetRenderWindow()->GetInteractor()->SetInteractorStyle(this->InteractorStyle); this->InteractorStyle->Init(); // Setup control of the viewing orientation this->ItkVtkCamera = new ITKVTKCamera(this->InteractorStyle->GetImageStyle(), this->Renderer, this->qvtkWidget->GetRenderWindow()); this->ItkVtkCamera->SetCameraPositionPNG(); }
void Vector() { typedef itk::Image<unsigned char, 2 > ChannelType; const unsigned int NumberOfChannels = 3; typedef itk::Image<itk::CovariantVector<unsigned char, NumberOfChannels>, 2 > ImageType; ImageType::Pointer image = ImageType::New(); itk::Index<2> corner = {{0,0}}; itk::Size<2> imageSize = {{500,500}}; itk::ImageRegion<2> fullRegion(corner, imageSize); image->SetRegions(fullRegion); image->Allocate(); for(unsigned int i = 0; i < NumberOfChannels; ++i) { itk::RandomImageSource<ChannelType>::Pointer randomImageSource = itk::RandomImageSource<ChannelType>::New(); randomImageSource->SetNumberOfThreads(1); // to produce non-random results randomImageSource->SetSize(imageSize); randomImageSource->Update(); ITKHelpers::SetChannel(image.GetPointer(), i, randomImageSource->GetOutput()); } itk::Size<2> patchSize = {{21,21}}; // There is nothing magic about these particular patches itk::Index<2> targetCorner = {{319, 302}}; itk::ImageRegion<2> targetRegion(targetCorner, patchSize); itk::Index<2> sourceCorner = {{341, 300}}; itk::ImageRegion<2> sourceRegion(sourceCorner, patchSize); Mask::Pointer mask = Mask::New(); mask->SetRegions(fullRegion); mask->Allocate(); ITKHelpers::SetImageToConstant(mask.GetPointer(), mask->GetValidValue()); typedef SumSquaredPixelDifference<ImageType::PixelType> PixelDifferenceType; typedef ImagePatchPixelDescriptor<ImageType> PatchType; ImagePatchDifference<PatchType, PixelDifferenceType> imagePatchDifference; PatchType targetPatch(image, mask, targetRegion); PatchType sourcePatch(image, mask, sourceRegion); float difference = imagePatchDifference(targetPatch, sourcePatch); std::cout << "GMHDifference: " << difference << std::endl; }
void CreateImage(ImageType* image) { itk::Index<2> corner = {{0,0}}; itk::Size<2> size = {{imageSize, imageSize}}; itk::ImageRegion<2> fullRegion(corner, size); image->SetRegions(fullRegion); image->Allocate(); itk::ImageRegionIterator<ImageType> imageIterator(image, image->GetLargestPossibleRegion()); int i = 0; while(!imageIterator.IsAtEnd()) { imageIterator.Set(i); i++; ++imageIterator; } }