Java Code Examples for net.imglib2.util.Pair#getA()

The following examples show how to use net.imglib2.util.Pair#getA() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommitCanvasN5.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static TLongHashSet generateContainedLabelsSet(
		final RandomAccessibleInterval<Pair<UnsignedLongType, LabelMultisetType>> relevantData)
{
	final TLongHashSet currentDataAsSet = new TLongHashSet();
	for (final Pair<UnsignedLongType, LabelMultisetType> p : Views.iterable(relevantData))
	{
		final UnsignedLongType  pa  = p.getA();
		final LabelMultisetType pb  = p.getB();
		final long              pav = pa.getIntegerLong();
		if (pav == Label.INVALID)
		{
			pb
					.entrySet()
					.stream()
					.map(Entry::getElement)
					.mapToLong(Label::id)
					.forEach(currentDataAsSet::add);
		}
		else
		{
			currentDataAsSet.add(pav);
		}
	}
	return currentDataAsSet;
}
 
Example 2
Source File: BackgroundCanvasIterable.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Iterator<LabelMultisetType> iterator() {
	return new Iterator<LabelMultisetType>() {

		final Iterator<? extends Pair<LabelMultisetType, UnsignedLongType>> iterator = backgroundAndCanvas.iterator();

		final Converter<UnsignedLongType, LabelMultisetType> conv = new FromIntegerTypeConverter<>();

		final LabelMultisetType type = FromIntegerTypeConverter.getAppropriateType();

		@Override
		public boolean hasNext() {
			return iterator.hasNext();
		}

		@Override
		public LabelMultisetType next() {
			final Pair<LabelMultisetType, UnsignedLongType> p = iterator.next();
			final UnsignedLongType b = p.getB();
			if (Label.regular(b.getIntegerLong())) {
				conv.convert(b, type);
				return type;
			} else
				return p.getA();
		}
	};
}
 
Example 3
Source File: MeshGeneratorJobManager.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private void setMeshVisibility(final Pair<MeshView, Node> meshAndBlock, final boolean isVisible)
{
	if (meshAndBlock.getA() != null)
		meshAndBlock.getA().setVisible(isVisible);

	if (meshAndBlock.getB() != null)
		meshAndBlock.getB().setVisible(isVisible);
}
 
Example 4
Source File: LinkOverlay.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public void setSelectedLink(Pair<Group<ViewId>, Group<ViewId>> link)
{
	if (link == null)
		selectedLink = null;
	else
		selectedLink = new ValuePair<>( link.getA(), link.getB() );
}
 
Example 5
Source File: DefaultFeretsAngle.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final Pair<RealLocalizable, RealLocalizable> input, final DoubleType output) {

	final RealLocalizable p1 = input.getA();
	final RealLocalizable p2 = input.getB();

	final double degree = Math.atan2(p2.getDoublePosition(1) - p1.getDoublePosition(1),
			p2.getDoublePosition(0) - p1.getDoublePosition(0)) * (180.0 / Math.PI);

	output.set(degree % 180);
}
 
Example 6
Source File: DefaultFeretsDiameter.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final Pair<RealLocalizable, RealLocalizable> input, final DoubleType output) {

	final RealLocalizable p1 = input.getA();
	final RealLocalizable p2 = input.getB();

	output.set(Math.hypot(p1.getDoublePosition(0) - p2.getDoublePosition(0),
			p1.getDoublePosition(1) - p2.getDoublePosition(1)));
}
 
Example 7
Source File: DefaultASCII.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public String calculate(final IterableInterval<T> input) {
	if (min == null || max == null) {
		final Pair<T, T> minMax = minMaxFunc.calculate(input);
		if (min == null) min = minMax.getA();
		if (max == null) max = minMax.getB();
	}
	return ascii(input, min, max);
}
 
Example 8
Source File: ExportSpimData2HDF5.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean queryParameters( SpimData2 spimData, final boolean is16bit )
{
	System.out.println( "queryParameters()" );

	if ( newTimepoints == null || newViewSetups == null )
	{
		IOFunctions.println( "new timepoints and new viewsetup list not set yet ... cannot continue" );
		return false;
	}

	perSetupExportMipmapInfo = Resave_HDF5.proposeMipmaps( newViewSetups );

	String fn = LoadParseQueryXML.defaultXMLfilename;
	if ( fn.endsWith( ".xml" ) )
		fn = fn.substring( 0, fn.length() - ".xml".length() );
	for ( int i = 0;; ++i )
	{
		Generic_Resave_HDF5.lastExportPath = String.format( "%s-f%d.xml", fn, i );
		if ( !new File( Generic_Resave_HDF5.lastExportPath ).exists() )
			break;
	}

	final int firstviewSetupId = newViewSetups.get( 0 ).getId();
	params = Generic_Resave_HDF5.getParameters( perSetupExportMipmapInfo.get( firstviewSetupId ), true, getDescription(), is16bit );

	if ( params == null )
	{
		System.out.println( "abort " );
		return false;
	}

	Pair< SpimData2, HashMap< ViewId, Partition > > init = initSpimData( newTimepoints, newViewSetups, params, perSetupExportMipmapInfo );
	this.spimData = init.getA();
	viewIdToPartition = init.getB();

	return true;
}
 
Example 9
Source File: RestrictPainting.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private static <T, U> void restrictTo(
		final RandomAccessible<Pair<T, U>> source,
		final RandomAccessible<UnsignedLongType> mask,
		final Localizable seed,
		final Shape shape,
		final Predicate<T> backgroundFilter,
		final Predicate<U> canvasFilter)
{
	final int n = source.numDimensions();

	final RandomAccessible<Pair<Pair<T, U>, UnsignedLongType>> paired = Views.pair(source, mask);

	final TLongList[] coordinates = new TLongList[n];
	for (int d = 0; d < n; ++d)
	{
		coordinates[d] = new TLongArrayList();
		coordinates[d].add(seed.getLongPosition(d));
	}

	final RandomAccessible<Neighborhood<Pair<Pair<T, U>, UnsignedLongType>>> neighborhood       = shape
			.neighborhoodsRandomAccessible(
			paired);
	final RandomAccess<Neighborhood<Pair<Pair<T, U>, UnsignedLongType>>>     neighborhoodAccess = neighborhood
			.randomAccess();

	final RandomAccess<UnsignedLongType> targetAccess = mask.randomAccess();
	targetAccess.setPosition(seed);
	targetAccess.get().set(1);

	final UnsignedLongType zero = new UnsignedLongType(0);
	final UnsignedLongType one  = new UnsignedLongType(1);
	final UnsignedLongType two  = new UnsignedLongType(2);

	for (int i = 0; i < coordinates[0].size(); ++i)
	{
		for (int d = 0; d < n; ++d)
		{
			neighborhoodAccess.setPosition(coordinates[d].get(i), d);
		}

		final Cursor<Pair<Pair<T, U>, UnsignedLongType>> neighborhoodCursor = neighborhoodAccess.get().cursor();

		while (neighborhoodCursor.hasNext())
		{
			final Pair<Pair<T, U>, UnsignedLongType> p                   = neighborhoodCursor.next();
			final UnsignedLongType                   m                   = p.getB();
			final Pair<T, U>                         backgroundAndCanvas = p.getA();
			if (m.valueEquals(zero) && canvasFilter.test(backgroundAndCanvas.getB()))
			{
				// If background is same as at seed, mark mask with two
				// (==not active), else with one (==active).
				m.set(backgroundFilter.test(backgroundAndCanvas.getA()) ? two : one);
				for (int d = 0; d < n; ++d)
				{
					coordinates[d].add(neighborhoodCursor.getLongPosition(d));
				}
			}

		}

		if (i > CLEANUP_THRESHOLD)
		{
			for (int d = 0; d < coordinates.length; ++d)
			{
				final TLongList c = coordinates[d];
				coordinates[d] = c.subList(i, c.size());
			}
			i = 0;
		}

	}
}
 
Example 10
Source File: TransformationTools.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static < A > Pair< A, A > reversePair( final Pair< A, A > pair )
{
	return new ValuePair< A, A >( pair.getB(), pair.getA() );
}
 
Example 11
Source File: PhaseCorrelation2Util.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static <T extends RealType<T>> List<PhaseCorrelationPeak2> getPCMMaxima(RandomAccessibleInterval<T> pcm, ExecutorService service, int maxN, boolean subpixelAccuracy){
	
	List<PhaseCorrelationPeak2> res = new ArrayList<PhaseCorrelationPeak2>();
	
	ArrayList<Pair<Localizable, Double>> maxima = FourNeighborhoodExtrema.findMaxMT(Views.extendPeriodic(pcm), pcm, maxN, service);
	//ArrayList<Pair<Localizable, Double>> maxima = FourNeighborhoodExtrema.findMax(Views.extendPeriodic(pcm), pcm, maxN);
	
	
			
	for (Pair<Localizable, Double> p: maxima){
		PhaseCorrelationPeak2 pcp = new PhaseCorrelationPeak2(p.getA(), p.getB());
		if (subpixelAccuracy)
			pcp.calculateSubpixelLocalization(pcm);

		res.add(pcp);
	}
	return res;		
}
 
Example 12
Source File: Data_Explorer.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run( String arg )
{
	if ( showNote )
	{
		showNote();
		showNote = false;
	}

	final LoadParseQueryXML result = new LoadParseQueryXML();

	result.addButton( "Define a new dataset", new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent e)
		{
			result.setReturnFalse( true );
			result.getGenericDialog().dispose();
			setDefineNewDataset();
		}
	});

	if ( !result.queryXML( "XML Explorer", "", false, false, false, false ) && !newDataset )
		return;

	final SpimData2 data;
	final String xml;
	final XmlIoSpimData2 io;

	if ( newDataset )
	{
		final Pair< SpimData2, String > dataset = new Define_Multi_View_Dataset().defineDataset( true );

		if ( dataset == null )
			return;

		data = dataset.getA();
		xml = dataset.getB();
		io = new XmlIoSpimData2( "" );
	}
	else
	{
		data = result.getData();
		xml = result.getXMLFileName();
		io = result.getIO();
	}

	final ViewSetupExplorer< SpimData2, XmlIoSpimData2 > explorer = new ViewSetupExplorer<SpimData2, XmlIoSpimData2 >( data, xml, io );

	explorer.getFrame().toFront();

	
}
 
Example 13
Source File: RemoveDetectionsPopup.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void actionPerformed( final ActionEvent e )
{
	if ( panel == null )
	{
		IOFunctions.println( "Panel not set for " + this.getClass().getSimpleName() );
		return;
	}

	if ( !SpimData2.class.isInstance( panel.getSpimData() ) )
	{
		IOFunctions.println( "Only supported for SpimData2 objects: " + this.getClass().getSimpleName() );
		return;
	}


	if ( index == 0 )
	{
		final List< ViewId > viewIds = panel.selectedRowsViewId();
		final SpimData2 data = (SpimData2)panel.getSpimData();

		// ask which channels have the objects we are searching for
		final List< ChannelProcessThinOut > channels = ThinOut_Detections.getChannelsAndLabels( data, viewIds );

		if ( channels == null )
			return;

		// get the actual min/max thresholds for cutting out
		if ( !ThinOut_Detections.getThinOutThresholds( data, viewIds, channels ) )
			return;

		// thin out detections and save the new interestpoint files
		if ( !ThinOut_Detections.thinOut( data, viewIds, channels, false ) )
			return;

		panel.updateContent(); // update interestpoint panel if available

		return;
	}
	else
	{
		final List< BasicViewDescription< ? extends BasicViewSetup > > vds = panel.selectedRows();

		if ( vds.size() != 1 )
		{
			JOptionPane.showMessageDialog( null, "Interactive Removal of Detections only supports a single view at a time." );
			return;
		}

		final Pair< String, String > labels = Interactive_Remove_Detections.queryLabelAndNewLabel( (SpimData2)panel.getSpimData(), (ViewDescription)vds.get( 0 ) );

		if ( labels == null )
			return;

		final SpimData2 spimData = (SpimData2)panel.getSpimData();
		final ViewDescription vd = (ViewDescription)vds.get( 0 );
		final ViewInterestPoints interestPoints = spimData.getViewInterestPoints();
		final ViewInterestPointLists lists = interestPoints.getViewInterestPointLists( vd );
		final String label = labels.getA();
		final String newLabel = labels.getB();

		final InteractiveProjections ip = new InteractiveProjections( spimData, vd, label, newLabel, 2 - (index - 1) );

		ip.runWhenDone( new Thread( new Runnable()
		{
			@Override
			public void run()
			{
				if ( ip.wasCanceled() )
					return;

				final List< InterestPoint > ipList = ip.getInterestPointList();

				if ( ipList.size() == 0 )
				{
					IOFunctions.println( "No detections remaining. Quitting." );
					return;
				}

				// add new label
				final InterestPointList newIpl = new InterestPointList(
						lists.getInterestPointList( label ).getBaseDir(),
						new File(
								lists.getInterestPointList( label ).getFile().getParentFile(),
								"tpId_" + vd.getTimePointId() + "_viewSetupId_" + vd.getViewSetupId() + "." + newLabel ) );

				newIpl.setInterestPoints( ipList );
				newIpl.setParameters( "manually removed detections from '" +label + "'" );

				lists.addInterestPointList( newLabel, newIpl );

				panel.updateContent(); // update interestpoint panel if available
			}
		}) );

		return;
	}
}
 
Example 14
Source File: AppendSpimData2HDF5.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean queryParameters( final SpimData2 spimData, final boolean is16bit )
{
	System.out.println( "queryParameters()" );

	if ( newTimepoints == null || newViewSetups == null )
	{
		IOFunctions.println( "new timepoints and new viewsetup list not set yet ... cannot continue" );
		return false;
	}

	Hdf5ImageLoader il = ( Hdf5ImageLoader ) spimData.getSequenceDescription().getImgLoader();

	perSetupExportMipmapInfo = Resave_HDF5.proposeMipmaps( newViewSetups );

	String fn = il.getHdf5File().getAbsolutePath();
	if ( fn.endsWith( ".h5" ) )
		fn = fn.substring( 0, fn.length() - ".h5".length() );
	String fusionHdfFilename = "";
	String fusionXmlFilename = "";
	for ( int i = 0;; ++i )
	{
		fusionHdfFilename = String.format( "%s-f%d.h5", fn, i );
		fusionXmlFilename = String.format( "%s-f%d.xml", fn, i );
		if ( !new File( fusionHdfFilename ).exists() && !new File( fusionXmlFilename ).exists() )
			break;
	}

	final int firstviewSetupId = newViewSetups.get( 0 ).getId();
	params = Generic_Resave_HDF5.getParameters( perSetupExportMipmapInfo.get( firstviewSetupId ), false, getDescription(), is16bit );
	if ( params == null )
	{
		System.out.println( "abort " );
		return false;
	}
	params.setHDF5File( new File( fusionHdfFilename ) );
	params.setSeqFile( new File( fusionXmlFilename ) );

	Pair< SpimData2, HashMap< ViewId, Partition > > init = ExportSpimData2HDF5.initSpimData(
			newTimepoints, newViewSetups, params, perSetupExportMipmapInfo );
	fusionOnlySpimData = init.getA();
	viewIdToPartition = init.getB();

	perSetupExportMipmapInfo.putAll(
			MergePartitionList.getHdf5PerSetupExportMipmapInfos( spimData.getSequenceDescription() ) );

	this.spimData = spimData;
	AppendSpimData2.appendSpimData2( spimData, newTimepoints, newViewSetups );

	ArrayList< Partition > mergedPartitions = MergePartitionList.getMergedHdf5PartitionList(
			spimData.getSequenceDescription(), fusionOnlySpimData.getSequenceDescription() );

	String mergedHdfFilename = "";
	for ( int i = 0;; ++i )
	{
		mergedHdfFilename = String.format( "%s-m%d.h5", fn, i );
		if ( !new File( mergedHdfFilename ).exists() )
			break;
	}

	SequenceDescription seq = spimData.getSequenceDescription();
	Hdf5ImageLoader newLoader = new Hdf5ImageLoader(
			new File( mergedHdfFilename ), mergedPartitions, seq, false );
	seq.setImgLoader( newLoader );
	WriteSequenceToHdf5.writeHdf5PartitionLinkFile( spimData.getSequenceDescription(), perSetupExportMipmapInfo );

	return true;
}