[vtk-developers] Problem with Rendering?

Marcus D. Hanwell marcus.hanwell at kitware.com
Thu Dec 30 13:15:31 EST 2010


Hi,

On Tue, Dec 28, 2010 at 6:07 PM, Martin Waitzbauer <mazzok at gmx.at> wrote:
> Hi there
>
> I have a problem with a vtkChartXY displaying 3 line plots
> i have defiuned scaler widgets to call a method, that sets the parameter for the line
>
> to di this
> i create a vtkTable, add 4 columns(column 0 is the x axis, 1-4 are the lines), set the number of rows(512), and fill column  1-3 with zeros
> (column zero is filled with user defined interval  values)
> thats the initializing part
> when the user use on of the scalers1-3, the double value is passed and draws line 1-3 with the passed value.
> this is done by

I am not sure I understand what you are trying to do here. You can
just make the plots invisible but remain too (SetVisible(false) on the
plot in question).
>
> setting the value of the column1-3 (representing a line) selected by scaler1-3 to the value (1-3)*SelectedScalerValue
> -add a vtkPLot o the chart
> -render the window
> -remove all plots fomr the chartxy

Why not use chart->ClearPlots()? That would remove all plots from the chart.
>
> the problem i have is that when the user uses scaler 1 , sets it to 1, line 1 is drawn with 1, so good for that
> but when the sclaer is set back to 0, the line at 1 is still there, and remains there even if the scaler is drawn towards higher numbers -> line at 1 is always there
>
> here is the code when the user hits a Scaler () used by Kwwidgets)
> column defines the TableColumn, value is the passed value
>
> void vtkContextView2::SetGaussData(int column, double scalerValue){
>        int c = this->Table->GetNumberOfColumns();
>        int r = this->Table->GetNumberOfRows();
>
>        //set the new Value
>        for(int i =0; i < 512;i++){
>                double v = scalerValue*column;
>                this->Table->SetValue(i,column,v);
>        }
>        //add new LinePlots to the Chart
>        int R [3]= {255, 0, 0};
>        int G [3]= {0, 255, 0};
>        int B [3]= {0, 0, 255};
>        for (int i = 1;i < c;i++){
>                vtkPlot *line = this->chart->AddPlot(vtkChart::LINE);
>                line->SetInput(this->Table, 0,i);
>                line->SetColor(R[i-1], G[i-1], B[i-1],255);
>                line->SetWidth(1.0);
>        }
>
>        //Render
>        this->RenderWindow->Render();
>
>        //Remove all Plots
>        for (int r = 1; r < c;r++){
>                this->chart->RemovePlot(r);
>        }
> }

As with most C++ arrays, vectors etc the index is 0 based - it looks
like you start at position 1. Also, removing plots like this looks
error prone as when you remove plot 1, plot 2 becomes plot 1, 3
becomes 2 etc. I am surprised this doesn't crash. I would recommend
using ClearPlots from the vtkChart API, or removing the relevant plot
pointer.

Hope that helps.

Marcus



More information about the vtk-developers mailing list