[vtkusers] I might learn something

Gibson,Thomas [Ontario] Thomas.Gibson at ec.gc.ca
Fri Sep 17 09:33:01 EDT 2004


How about:

float center[3];
center[0] = (pt1[0]+ pt2[0])*0.5;
center[1] = (pt1[1]+ pt2[1])*0.5;
center[2] = (pt1[2]+ pt2[2])*0.5;

	instead?

> -----Original Message-----
> From: vtkusers-bounces at vtk.org 
> [mailto:vtkusers-bounces at vtk.org] On Behalf Of Dean Inglis
> Sent: September 17, 2004 9:36 AM
> To: vtkusers archive
> Subject: Re: [vtkusers] I might learn something
> 
> 
> 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
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> 
> 
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: 
<http://public.kitware.com/cgi-bin/vtkfaq>
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list