[vtkusers] I might learn something

James Robinson j.robinson at kepler-systems.com
Fri Sep 17 05:57:37 EDT 2004


Dear All,

 

I came across this code in vtkPlaneWidget. It is to calculate the centre of
the plane source:

 

  float center[3];

  center[0] = o[0] + (pt1[0]-o[0])/2.0 + (pt2[0]-o[0])/2.0;

  center[1] = o[1] + (pt1[1]-o[1])/2.0 + (pt2[1]-o[1])/2.0;

  center[2] = o[2] + (pt1[2]-o[2])/2.0 + (pt2[2]-o[2])/2.0;

 

 

Isn't this exactly the same as:

  float center[3];

  center[0] = (pt1[0]+ pt2[0])/2.0;

  center[1] = (pt1[1]+ pt2[1])/2.0;

  center[2] = (pt1[2]+ pt2[2])/2.0;

 

but doubles the number of operations???? I may be missing something
(sometimes the most obvious concept is the one that eludes us) and I always
want to learn something that could improve my programming technique. If I am
correct, then is such programming having an adverse effect on the speed of
vtk overall? (It may be that (a) there aren't many instances of such coding
and (b) these types of calculations are insignificant in cost versus the
core of the rendering etc.).

 

Jim

 

Jim Robinson

*     42 Rivergrove,

         Glanmire,

         Co. Cork,

         Eire

'     +353 21 4822028

         +353 87 2393010

*       jrobinson at eircom.net

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040917/8c3b210a/attachment.htm>


More information about the vtkusers mailing list