[vtkusers] Need for spherical to cartesian nonlinear transformation.

David Gobbi dgobbi at irus.rri.ca
Mon Mar 25 16:19:39 EST 2002


Hi Roland,

I've committed the vtkSphericalTransform as well as a
vtkCylindricalTransform (they're almost identical, code-wise).

The range problem (i.e. [0,2*pi] instead of [-pi,+pi]) has
been fixed, though it is indeed arbitrary...  it just seems
to make more sense to have the disconinuity at 0.0 and 2*pi.

The discontinuity fix was done via
  theta = pi + atan2(-y, -x);
which is much more efficient than adding an extra 'if' statement.
(Note that most VTK developers avoid the ?: operator like the plague).

The Jacobian matrix is being computed correctly.  Note this chunk
of code in vtkWarpTransform.cxx that inverts the matrix:

template<class T>
inline static void vtkWarpTransformDerivative(vtkWarpTransform *self,
                                              int inverse,
                                              const T input[3],
                                              T output[3],
                                              T derivative[3][3])
{
  if (inverse)
    {
    self->TemplateTransformInverse(input,output,derivative);
    vtkMath::Invert3x3(derivative,derivative);
    }
  else
    {
    self->TemplateTransformPoint(input,output,derivative);
    }
}

I don't like having separate code for the forward & inverse
Jacobian calculation, since the inverse Jacobian can be computed
so easily from the forward Jacobian.

 - David

--
  David Gobbi, MSc                       dgobbi at irus.rri.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario

On Fri, 22 Mar 2002, Roland Schwarz wrote:

> On more observation:
>
> I just had a look on the inverse derivatives, and pulled out my math books.
> I think there is a error in them.
>
> You are using the same formula for the inverse transformation as you do for
> transformation.
> The matrix product of both the matices must equal the unity matrix. This is
> how the derivative of the inverse function is defined.
> This will not give unity in your case, as far as I see.
>
> I've appended, what I think is correct to this mail.
> Also I've avoided to express the inverse derivative as functions of
> r,phi,theta, which would result when doing a simple matix inversion. This
> also removes the need to call cos() and sin().
>
> Also I've done a little modification to the back transformation that saves
> one call to a transzendent function (sqrt()). The atan2 also has the
> property that it is 'discontinuous' at -Pi/2 instead of Pi. I've moved this
> to map rectangular coordinates to the range from 0 ... 2*Pi, which is also
> somewhat arbitrary. Best would be to have a parameter that controls the
> starting angle.
>
> Perhaps I can make a little example too when I have some spare time. I'am
> thinking of projecting the vtkEarthSource to a flat space. What do you
> think? (BTW.: This is similar to my problem at hand since I am processing
> data from a scanning device that basically gets data in spherical
> coordinates.)
>
> Unfortunately I do not yet have an idea of how one could visualize the
> correctness of the inverse derivative. Is there a warping example that could
> do the job? Perhaps I'll find an example from my books. Should be some
> vector example I think?
>
> Have a nice weekend,
> Roland
>
>
>
> ----- Original Message -----
> From: "David Gobbi" <dgobbi at irus.rri.ca>
> To: "Roland Schwarz" <roland.schwarz at chello.at>
> Cc: "vtk-users" <vtkusers at public.kitware.com>
> Sent: Thursday, March 21, 2002 5:54 PM
> Subject: Re: [vtkusers] Need for spherical to cartesian nonlinear
> transformation.
>
>
> > On Thu, 21 Mar 2002, Roland Schwarz wrote:
> >
> > > Thank you again,
> > >
> > > it worked.
> > >
> > > But could you please give me your rationale for the specific ordering of
> the
> > > spherical coordinates?
> > > I might consider adopting your ordering.
> > >
> > > As a matter of facts my ordering is opposite:
> > > Namely radius, azimuth angle [0..360 deg], polar angle[0..180 deg]
> >
> > The order I used was just the order given in my 1st year calculus
> > text.
> >
> > > Is this because the local system, that is defined by the derivative is
> right
> > > handed in your case?
> >
> > Nothing so deep as that.  What I'll do is check through the VTK classes
> > to see if spherical coordinates are used anywhere else, and ensure that
> > the vtkShericalTransform agrees with the conventions use in the rest
> > of VTK.
> >
> > > Thank you for your effort.
> >
> > You're very welcome.
> >
> >  - David
> >
> > _______________________________________________
> > 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://public.kitware.com/mailman/listinfo/vtkusers
> >
>




More information about the vtkusers mailing list