[vtkusers] Float to Int

Patrícia Gonçalves pgoncalves at inegi.up.pt
Tue Jul 18 12:56:33 EDT 2006


Hi!

I'm not sure I understood your problem...

I imagine you have something like this:
  float j = 0.8983f;
  int i = (int)j;
making i=0.

If you're using .NET you can use the Math::Round method:
  float j = 0.8983f;
  int i = (int)Math::Round(j);
making i=1.

Hope this helps!

 




  ----- Original Message ----- 
  From: Ali Calvert 
  To: vtkusers at vtk.org 
  Sent: Tuesday, July 18, 2006 5:33 PM
  Subject: [vtkusers] Float to Int


  Hi all, i'm having a bit of difficulty converting my texture coordinates (as a float from 0 -> 1) to a coordinate (as an integer from 0 - > size of image)  My current method simply floors the float, i.e. 0.8983 would be a 0, however this isn't very accurate as it should be a 1. 

  Can anybody help me please?

  Also if there is a better way of doing this rather than rounding, i would appreciate any comments.

  Thank you for your time.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060718/a7ba1040/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 23294 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060718/a7ba1040/attachment.jpeg>


More information about the vtkusers mailing list