[vtkusers] vtkVolumeProperty SetColor (a bug in vtkVolume)

Weiguang Guan guanw at rhpcs.mcmaster.ca
Mon Nov 8 15:02:31 EST 2004


Hi VTK users,

Since nobody responds to my previous email I started looking into the 
problem myself. I found the bug was at
	void vtkVolume::UpdateTransferFunctions( vtkRenderer 
*vtkNotUsed(ren) )
 
......
    // How many color channels for this component?
    colorChannels = this->Property->GetColorChannels(c);

    // If we have 1 color channel and no gray array, create it.
    // Free the rgb array if there is one.
    if ( colorChannels == 1 && !this->GrayArray[c] )
      {
      if ( this->RGBArray[c] )
        {
        delete [] this->RGBArray[c];
        this->RGBArray[c]= NULL; // My fix
        }
      this->GrayArray[c] = new float[arraySize];
      }

    // If we have 3 color channels and no rgb array, create it.
    // Free the gray array if there is one.
    if ( colorChannels == 3 && !this->RGBArray[c] )
      {
      if ( this->GrayArray[c] )
        {
        delete [] this->GrayArray[c];
        this->GrayArray[c] = NULL; // My fix
        }
      this->RGBArray[c] = new float[3*arraySize];
      }
.......

Two statements added to fix the bug are labeled with " // My 
fix". 

In addition, I think it would make more sense if the code is written as 
follows:
    // How many color channels for this component?
    colorChannels = this->Property->GetColorChannels(c);

    // If we have 1 color channel and no gray array, create it.
    // Free the rgb array if there is one.
    if ( colorChannels == 1 )
      {
      if ( this->RGBArray[c] )
        {
        delete [] this->RGBArray[c];
        this->RGBArray[c]= NULL;
        }
      if ( !this->GrayArray[c] )
        this->GrayArray[c] = new float[arraySize];
      }

    // If we have 3 color channels and no rgb array, create it.
    // Free the gray array if there is one.
    if ( colorChannels == 3 )
      {
      if ( this->GrayArray[c] )
        {
        delete [] this->GrayArray[c];
        this->GrayArray[c] = NULL;
        }
      if ( !this->RGBArray[c] )
        this->RGBArray[c] = new float[3*arraySize];
      }

I'd like to hear your comments, especially from Kitware.

Weiguang

-- 
========================================================
Weiguang Guan, Research Engineer
RHPCS, McMaster University
========================================================
On Mon, 1 Nov 2004, Weiguang Guan wrote:

> Hi everyone,
> 
> I'm not sure whether this is a bug and it's been reported or not if it's a 
> bug.
> 
> While I design a GUI to let user choose between gray and color transfer
> functions in volume raycasting the program crashed with segmentation
> fault. I checked the vtkVolumeProperty.* and found that the MTime of gray 
> or color won't get updated if one uses the same vtkPiecewiseFunction (or 
> vtkColorTransferFunction) pointer as arg of SetColor even though the 
> transfer function object itself has changed (using AddPoints for example).
> 
> What puzzles me is that the program crashed as well if I create a new 
> vtkPiecewiseFunction (or vtkColorTransferFunction) each time I'm going to 
> change transfer function.
> 
> Am I use it in the way it is supported to.
> 
> Weiguang
> 
> 




More information about the vtkusers mailing list