[vtkusers] I might learn something

Dean Inglis dean.inglis at camris.ca
Fri Sep 17 09:36:09 EDT 2004


Hi Jim,

>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;

is mathematically 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 is certainly not as efficient, as you pointed out.
If no-one beats me to it, I'll check in a change.
Don't we all code things in a manner that
makes sense to ourselves/promotes clarity/etc. at the time?

Dean


>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.).





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dean Inglis, PhD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~ Center for Appendicular ~~~~~
Magnetic Resonance Imaging Studies
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
610 - 25 Charlton Ave. E.
Hamilton, Ontario, L8N 1Y2
tel:
fax:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Adjunct Professor
Department of Civil Engineering
McMaster University
Hamilton, Ontario
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~







More information about the vtkusers mailing list