[vtkusers] Why is the image red?
David Doria
daviddoria+vtk at gmail.com
Mon Dec 14 20:02:55 EST 2009
On Mon, Dec 14, 2009 at 6:05 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> On Mon, Dec 14, 2009 at 3:45 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
>
>> David G,
>>
>> I guess I still don't follow you why it is so bad to create an image
>> the way I had? I'll trust you though and I changed it to use a
>> vtkImageCanvasSource2D to generate the blank image (I had to use
>> FillBox on the whole image though because it wasn't initialized).
>
> There are three reasons why it is bad.
>
> 1) If people directly access the data objects in VTK, it makes it
> impossible for the developers to change their interface methods
> because of backwards compatibility concerns.
>
> 2) One of the great things about the pipeline redesign in VTK 5 is
> that, for the most part, people no longer have to directly access the
> data objects. And we should not encourage them to. See #1 and #3
> below.
>
> 3) People who create data objects by hand are likely to want to do
> things like get the output from a filter and use
> SetScalarComponentFromDouble() on it to change the color of a pixel.
> But guess what? The next time the pipeline updates, the pixel will be
> overwritten. The outputs of all filters should be considered "const"
> but they cannot be because VTK cannot be redesigned to that extent
> (see backwards compatibility). So at the very least, users should be
> strongly discouraged from modifying output data, and at best, they
> should never even touch the output data objects.
>
> For the rest of your questions, see the source code, because that's
> what I'd have to do in order to answer them. I wouldn't be surprised
> if CanvasSource2D is more than a little buggered.
>
> David
>
Ok, so I simply had to
drawing->SetNumberOfScalarComponents(3);
I guess it was 1 by default, so it was then only using the first
component of DrawColor.
What is the deal with this loop/why do people write such cryptic
code!!? It is exactly this type of thing that prevents me from "using
the code as the documentation", which sounds like a reasonable idea in
an ideal world.
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
More information about the vtkusers
mailing list