-
Notifications
You must be signed in to change notification settings - Fork 95
Simple Conversion between RealTypes #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm not sure about the names of the static methods, or to which class the should belong: And I think about adding more functionality: Converters that bound the value to minimum and maximum. And converters allow to scale the values. |
@StephanPreibisch @axtimwalde I just noticed (because this PR touches it), that Do you remember what the reason was to do it like this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the names of the static methods, or to which class the should belong:
RealConverters.getConverter
,RealConverters.convert
and especiallyCopyPixels.fromTo
.
I like RealTypeConverters.getConverter
and RealTypeConverters.convert
.
CopyPixels.fromTo
is not good.
The name hides the fact that it converts between types.
Also, placed in a unrelated CopyPixels
class, it is weird that it is limited to RealType
.
I would like RealTypeConverters.copyConverted(...)
better.
A general copy-pixels method would be nice though.
(There is ImgUtil.copy(...)
but it's very specific. Maybe could be deprecated when something more general is available).
I would change signature to the source
being only RandomAccessible
(not Interval
), so that it can be used to fill pixels of an output interval from a potentially unbounded source.
Then I could imagine to have a CopyPixels
class with more methods where the converted copy would fit in. E.g.
public final class CopyPixels
{
public static < T extends Type< T > > void copy(
RandomAccessible< T > source,
RandomAccessibleInterval< T > destination )
{...}
public static void copyReal(
RandomAccessible< ? extends RealType< ? > > source,
RandomAccessibleInterval< ? extends RealType< ? > > destination )
{...}
}
And I think about adding more functionality: Converters that bound the value to minimum and maximum. And converters allow to scale the values.
I think this is a good idea, but could probably be done later in a separate PR.
} | ||
} | ||
|
||
public static class DoubleConverter implements Converter< RealType< ? >, RealType< ? > > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With these classes being public
could you add javadoc, please.
Can be very minimal, e.g.,
/**
* Converts via {@link RealType#getRealDouble}.
*/
is better than nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
The complicated code, that implements many different converters and decides which one to use, is now nicely separated from the public API. The classes RealTypeConverters.DoubleType previously were public to allow the use of ClassCopyProvider. No they are package-private but ClassCopyProcider can still be applied.
@tpietzsch I did the changes you requested:
|
@maarzt I merged this accidentaly, now force-pushed to master to undo that. |
I'll review and then merge locally... |
ok, merged now... |
When I need to convert between two RealTypes a usally us a lambda expression like this:
But this converter is not optimal in term of performance (To convert ByteType -> IntType you would not need do cast to double), a precision (UnsignedLongType can be poorly represented as double).
This PR adds three methods to fix this: