[vtk-developers] vtkVectorOperators

David Lonie loniedavid at gmail.com
Mon Jan 23 10:58:37 EST 2012


On Mon, Jan 23, 2012 at 7:16 AM, Marcus D. Hanwell
<marcus.hanwell at kitware.com> wrote:
> Many of these functions are in a separate header, called
> vtkVectorOperators.h, along with tests in
> Common/Testing/Cxx/TestVectorOperators.cxx. I think it is missing
> scalar multiplication, and possible negation (would have to check). As
> you have everything working without, I can review the branch as is and
> then perhaps get it using some of the operators again at some point in
> the future.

I took a stab at implementing these, but I've run into a
metaprogramming issue that I'm not familiar with. I've put up a draft
here:

https://github.com/dlonie/VTK/commit/674474eabc45f38be7eac1406039326141c059e9

The trouble seems to be in the macros used to generate the operators
for the predefined types. I get this rather cryptic compiler error:

/usr/src/vtk/Common/vtkVectorOperators.h: In function 'vtkVector2i&
operator+=(vtkVector2i&, const vtkVector2i&)':
/usr/src/vtk/Common/vtkVectorOperators.h:379:1: error: no match for
'operator+=' in '(&
v1)->vtkVector2i::<anonymous>.vtkVector2<int>::<anonymous> += (&
v2)->vtkVector2i::<anonymous>.vtkVector2<int>::<anonymous>'
/usr/src/vtk/Common/vtkVectorOperators.h:379:1: note: candidates are:
/usr/src/vtk/Common/vtkVectorOperators.h:88:22: note: vtkVector<A,
Size>& operator+=(vtkVector<A, Size>&, const vtkVector<A, Size>&)
[with A = int, int Size = 2]
/usr/src/vtk/Common/vtkVectorOperators.h:88:22: note:   no known
conversion for argument 1 from 'vtkVector<int, 2>' to 'vtkVector<int,
2>&'
/usr/src/vtk/Common/vtkVectorOperators.h:379:1: note: vtkVector2i&
operator+=(vtkVector2i&, const vtkVector2i&)
/usr/src/vtk/Common/vtkVectorOperators.h:379:1: note:   no known
conversion for argument 1 from 'vtkVector<int, 2>' to 'vtkVector2i&'

The preprocessor shows the macro expanding to:

inline vtkVector2i operator+(const vtkVector2i& v1, const vtkVector2i&
v2) { return vtkVector2i((static_cast<vtkVector<int, 2> >(v1) +
static_cast<vtkVector<int, 2> >(v2)).GetData()); } inline vtkVector2i
& operator+=(vtkVector2i& v1, const vtkVector2i& v2) { return
static_cast<vtkVector2i>(static_cast<vtkVector<int, 2> >(v1) +=
static_cast<vtkVector<int, 2> >(v2)); } inline vtkVector2i
operator-(const vtkVector2i& v1, const vtkVector2i& v2) { return
vtkVector2i((static_cast<vtkVector<int, 2> >(v1) -
static_cast<vtkVector<int, 2> >(v2)).GetData()); } ... [snip]

Seems like the trouble could be the static cast from vtkVector<Type,
Size> to vtkVectorXX (see the last line of the compiler snippet), but
the rest of the output makes no sense to me, so I'm not sure ;-) What
would be the most efficient way to cast the vtkVector<,> to a
vtkVectorXX?

Dave



More information about the vtk-developers mailing list