[vtkusers] Why is the image red?
David Gobbi
david.gobbi at gmail.com
Tue Dec 15 19:59:26 EST 2009
I'd have to say that I don't know. Are you willing to do some VTK
code profiling with the intel compiler?
David
On Tue, Dec 15, 2009 at 5:42 PM, Allan James <ar.james at qut.edu.au> wrote:
>
> Hi David,
>
> Doesn't the use of pointer arithmetic within loops like this prevent certain compilers (for example - Intel) from performing automatic vectorization?
>
> I'm pretty sure the Intel compilers will ignore such loops - which is a shame because the performance increase can be significant..
>
> Cheers,
>
> Allan James
> High Performance Computing & Research Support
> Queensland University of Technology
> (07) 3138 9264
> ar.james at qut.edu.au
> http://www.qut.edu.au/its/hpc
>
>><(((º> ._.·´¯`·.. >++(((º> ._.·´¯`·.. >++(((º>
>
>> On Mon, Dec 14, 2009 at 6:02 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
>> >
>> > ? ? ?ptr = static_cast<T *>(image->GetScalarPointer(p0, p1, z));
>> >
>> > ? ? ?pf = drawColor;
>> > ? ? ?// Assign color to pixel.
>> > ? ? ?for (idxV = 0; idxV <= maxV; ++idxV)
>> > ? ? ? ?{
>> > ? ? ? ?*ptr = static_cast<T>(*pf++);
>> > ? ? ? ?ptr++;
>> > ? ? ? ?}
>> >
>> > Couldn't this be simply:
>> >
>> > // Assign color to pixel.
>> > for (component = 0; component <= maxV; ++component)
>> > ?{
>> > ?image->SetScalarComponentFromDouble(p0, p1, z, component, drawColor[i]);
>> > ?}
>> >
>> > This function is a template function which is called with
>> > vtkTemplateMacro. I don't understand what that is doing - isn't the
>> > whole point of templates that you don't have to declare all of these
>> > different types explicitly?
>> >
>> > Thanks,
>> >
>> > David
>>
>> All of the VTK imaging filters work by doing pointer arithmetic and
>> direct access to memory. It's the VTK convention. It's possibly not
>> the best way for things to be done, but after you're familiar with the
>> common pointer arithmetic coding patters it's easy to read this code
>> and see what it's doing. Really, if the main problem that I see is
>> that the variables weren't named very well.
>>
>> The SetScalarComponentFromDouble() method isn't 100% inlined and it
>> involves a virtual function call, so it's far too inefficient to use
>> inside an image filter. Not to mention that it does a few
>> multiplications and additions internally. Yikes.
>>
>> The big "switch" in the vtkTemplateMacro allows the execute methods to
>> be templated while the classes themselves aren't. Because the filter
>> classes themselves aren't templated, an instance of a vtk filter class
>> can actually operate on any data type that you feed it. In contrast
>> with e.g. ITK where filter instances are type specific.
>>
>> David
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list