QDomElement lastfm::Track::toDomElement( QDomDocument& xml ) const { QDomElement item = xml.createElement( "track" ); #define makeElement( tagname, getter ) { \ QString v = getter; \ if (!v.isEmpty()) \ { \ QDomElement e = xml.createElement( tagname ); \ e.appendChild( xml.createTextNode( v ) ); \ item.appendChild( e ); \ } \ } makeElement( "artist", d->artist ); makeElement( "albumArtist", d->albumArtist ); makeElement( "album", d->album ); makeElement( "track", d->title ); makeElement( "correctedArtist", d->correctedArtist ); makeElement( "correctedAlbumArtist", d->correctedAlbumArtist ); makeElement( "correctedAlbum", d->correctedAlbum ); makeElement( "correctedTrack", d->correctedTitle ); makeElement( "duration", QString::number( d->duration ) ); makeElement( "timestamp", QString::number( d->time.toTime_t() ) ); makeElement( "url", d->url.toString() ); makeElement( "source", QString::number( d->source ) ); makeElement( "rating", QString::number(d->rating) ); makeElement( "fpId", QString::number(d->fpid) ); makeElement( "mbId", mbid() ); makeElement( "loved", QString::number( isLoved() ) ); makeElement( "scrobbleStatus", QString::number( scrobbleStatus() ) ); makeElement( "scrobbleError", QString::number( scrobbleError() ) ); // put the images urls in the dom QMapIterator<lastfm::ImageSize, QUrl> imageIter( d->m_images ); while (imageIter.hasNext()) { QDomElement e = xml.createElement( "image" ); e.appendChild( xml.createTextNode( imageIter.next().value().toString() ) ); e.setAttribute( "size", imageIter.key() ); item.appendChild( e ); } // add the extras to the dom QDomElement extras = xml.createElement( "extras" ); QMapIterator<QString, QString> extrasIter( d->extras ); while (extrasIter.hasNext()) { QDomElement e = xml.createElement( extrasIter.next().key() ); e.appendChild( xml.createTextNode( extrasIter.value() ) ); extras.appendChild( e ); } item.appendChild( extras ); return item; }
static void CreateNoNaNMask(itk::Image<TPixel, VImageDimension>* itkValue, mitk::Image::Pointer mask, mitk::Image::Pointer& newMask) { typedef itk::Image< TPixel, VImageDimension> LFloatImageType; typedef itk::Image< unsigned short, VImageDimension> LMaskImageType; typename LMaskImageType::Pointer itkMask = LMaskImageType::New(); mitk::CastToItkImage(mask, itkMask); typedef itk::ImageDuplicator< LMaskImageType > DuplicatorType; typename DuplicatorType::Pointer duplicator = DuplicatorType::New(); duplicator->SetInputImage(itkMask); duplicator->Update(); auto tmpMask = duplicator->GetOutput(); itk::ImageRegionIterator<LMaskImageType> mask1Iter(itkMask, itkMask->GetLargestPossibleRegion()); itk::ImageRegionIterator<LMaskImageType> mask2Iter(tmpMask, tmpMask->GetLargestPossibleRegion()); itk::ImageRegionIterator<LFloatImageType> imageIter(itkValue, itkValue->GetLargestPossibleRegion()); while (!mask1Iter.IsAtEnd()) { mask2Iter.Set(0); if (mask1Iter.Value() > 0) { // Is not NaN if (imageIter.Value() == imageIter.Value()) { mask2Iter.Set(1); } } ++mask1Iter; ++mask2Iter; ++imageIter; } newMask->InitializeByItk(tmpMask); mitk::GrabItkImageMemory(tmpMask, newMask); }
static int CalculateGlSZMatrix(itk::Image<TPixel, VImageDimension>* itkImage, itk::Image<unsigned short, VImageDimension>* mask, std::vector<itk::Offset<VImageDimension> > offsets, bool estimateLargestRegion, mitk::GreyLevelSizeZoneMatrixHolder &holder) { typedef itk::Image<TPixel, VImageDimension> ImageType; typedef itk::Image<unsigned short, VImageDimension> MaskImageType; typedef typename ImageType::IndexType IndexType; typedef itk::ImageRegionIteratorWithIndex<ImageType> ConstIterType; typedef itk::ImageRegionIteratorWithIndex<MaskImageType> ConstMaskIterType; auto region = mask->GetLargestPossibleRegion(); typename MaskImageType::RegionType newRegion; newRegion.SetSize(region.GetSize()); newRegion.SetIndex(region.GetIndex()); ConstIterType imageIter(itkImage, itkImage->GetLargestPossibleRegion()); ConstMaskIterType maskIter(mask, mask->GetLargestPossibleRegion()); typename MaskImageType::Pointer visitedImage = MaskImageType::New(); visitedImage->SetRegions(newRegion); visitedImage->Allocate(); visitedImage->FillBuffer(0); int largestRegion = 0; while (!maskIter.IsAtEnd()) { if (maskIter.Value() > 0 ) { auto startIntensityIndex = holder.IntensityToIndex(imageIter.Value()); std::vector<IndexType> indices; indices.push_back(maskIter.GetIndex()); unsigned int steps = 0; while (indices.size() > 0) { auto currentIndex = indices.back(); indices.pop_back(); if (!region.IsInside(currentIndex)) { continue; } auto wasVisited = visitedImage->GetPixel(currentIndex); auto newIntensityIndex = holder.IntensityToIndex(itkImage->GetPixel(currentIndex)); auto isInMask = mask->GetPixel(currentIndex); if ((isInMask > 0) && (newIntensityIndex == startIntensityIndex) && (wasVisited < 1)) { ++steps; visitedImage->SetPixel(currentIndex, 1); for (auto offset : offsets) { auto newIndex = currentIndex + offset; indices.push_back(newIndex); newIndex = currentIndex - offset; indices.push_back(newIndex); } } } if (steps > 0) { largestRegion = std::max<int>(steps, largestRegion); steps = std::min<unsigned int>(steps, holder.m_MaximumSize); if (!estimateLargestRegion) { holder.m_Matrix(startIntensityIndex, steps - 1) += 1; } } } ++imageIter; ++maskIter; } return largestRegion; }