Are there any classes, methods in the .NET library, or any algorithms in general, to perform non-affine transformations? (i.e. transformations that involve more than just rotation, scale, translation and shear)
e.g.:
Is there another term for non-affine transformations?
-
All of the example images you posted can be done with a Quadrilateral Distortion. Though I cant say for certain that a quad distort will cover ALL non affine transforms.
Heres a link to a not so good implementation of it in C#... it works, but is slow. Poke around Wikipedia for the many different optimizations available for these kinds of calculations
http://www.vcskicks.com/image-distortion.html
-Neil
kquinn : "Though I cant say for certain that a quad distort will cover ALL non affine transforms." It won't, there are many, many things a quad distort can't do. But it's an excellent start. -
I am not aware of anything integrated in .Net letting you do non affine transforms.
I guess you are trying to have some sort of 3D texture mapping? If that's the case you need an homogenous affine transform, which is not available in .Net. I'm also not aware of any integrated way to make pixel displacement transforms in .Net.
However, the currently voted solution might be good for what you are trying to do, just be aware that it won't do perspective correction out of the box.
For instance:
The picture on the left was generated using the single quad distort library provided by Neil N. The picture on the right was generated using a single quad (two triangles actually) in DirectX.
This may not have any impact on what you are trying to do, but this is something to keep in mind if you want to do 3D stuff, it will look very weird without perspective correct mapping.
Ian Boyd : No, we got an iPod, and i saw the page-wrap-up ability. And i was disgusted that a tiny embedded device, and flash, can no fancy transformations - but a Core2 Duo running the most advanced operating system in the world cannot.Ian Boyd : "...can do* fancy transformations..."Neil N : Just because it doesnt have built in functions to do fancy transforms doesnt mean it can't do it. I've seen some pretty amazing graphics doen in pure C#Coincoin : With the link Neil provided you, you can do what you want. It will do good 3D, although not perspective correct, but it should not matter if your polygons stay small.Neil N : Actually the link I provided WOULD allow for perspective correct transforms, if used properly.Coincoin : If used on sufficiently small polygons and the user provides perspective corrected mappings herself, yes you can achieve a similar effect. But from what I can see, the library as-is do not provide perspective corrected mapping.Neil N : "From what you can see" ?? how about being sure before making false statements. The linked algorithm computes EACH PIXEL, no need to break it up into polygons.Coincoin : Neil N: The algorithm is a quad mapper, what it does is affine mapping. With only 2D coordinates, there is no way this is doing perspective correct mapping. If you still have doubt after this comment, I invite you to do research on what "perspective correct texture mapping" is.Neil N : Coincoin, calculating corner intersection is a perspective correct method. It may not be the method you are familiar with, but it works. You can even test it against other perspective correct methods, you will not see any difference. This is a fact.Coincoin : I updated my answer to give more details about the problems that might arise if simple distortions are used versus perspective corrected. As you can see, I tested the library against a perspective correct method (DirectX) and the difference is clear.Coincoin : Now, I know there are ways to have perspective without resorting to a full 3D system, assuming we have a source rectangle and a target quad, however, the library just doesn't seem to do it, unless I missed somethingNeil N : My mistake, I assumed because it used corner intersection that it was correct. After looking deeper, it uses it incorrectly.Ian Boyd : And this is still a very useful answer, as you took the time to post a picture showing the difference between a distortion and a perspective correction. In my case i was wanting to do a perspective correction - taking what looks like a flat piece of paper and having it rotated -
You can do this in wpf using a the Viewport3d control and a non-affine transform matrix. Rendering this to a bitmap again may be interesting.... Which I "fixed" by including an invisible <image> control with the same image as on my textured plane... (Also, I've had to work around the max texture size issues by splitting up the plane and cropping images...)
http://www.charlespetzold.com/blog/2007/08/060605.html
In my case I wanted the reverse of this (transform so arbitrary points on the warped become the corners of my rectangular window), which is the Inverse of the matrix to do the opposite.
sphereinabox : Oh, Charles Petzold also posted how to do this in silverlight 3 using the Matrix3dProjection: http://www.charlespetzold.com/blog/2009/07/Using-the-Matrix3DProjection-Class-in-Silverlight-3.html
0 comments:
Post a Comment