[vtkusers] Activiz and vtkChartXY

Eric E. Monson emonson at cs.duke.edu
Wed Feb 23 15:10:47 EST 2011


Hello,

I've never tried to do it before, but it made me curious. I got as far as being able to display the chart without the extra window popping up, but every effort to get the interactor to work gave me the extra window and a crash on exit. 

This type of problem arises with the QVTKWidget when using vtkRenderView and vtkContextView descendants, but you can get around it by swapping the interactor and render window back and forth between the two like in EasyView.cxx, or in Python (without SIP bindings) with the QVTKRenderWindowInteractor I've gotten it to work by passing the render window from the vtkContextView to the constructor of the widget.

But, with the .NET bindings and the RenderWindowControl you can't set the render window or pass it one when you first create it, and all of the combinations I've tried with setting the vtkContextView's interactor or grabbing one from the render window haven't worked...

Here's my code in case it gets you a little further, but we'll have to hope that someone else out there has tried to get a vtkView into a window with the .NET bindings...

-Eric

------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group


        private void renderWindowControl1_Load(object sender, EventArgs e)
        {
            // Set up a 2D scene
            vtkContextView view = vtkContextView.New();

            // Create components of the rendering subsystem
            //
            vtkRenderWindow renWin = renderWindowControl1.RenderWindow;

            renderWindowControl1.RenderWindow.RemoveRenderer(renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer());
            renderWindowControl1.RenderWindow.AddRenderer(view.GetRenderer());
            view.GetRenderer().SetBackground(1, 1, 1);

            vtkChartXY chart = vtkChartXY.New();
            view.GetScene().AddItem(chart);

            int numPoints = 40;

            vtkDoubleArray arrX = vtkDoubleArray.New();
            arrX.SetName("X Axis");
            arrX.SetNumberOfComponents(1);
            arrX.SetNumberOfValues(numPoints);
            vtkDoubleArray arrC = vtkDoubleArray.New();
            arrC.SetName("Cosine");
            arrC.SetNumberOfComponents(1);
            arrC.SetNumberOfValues(numPoints);
            vtkDoubleArray arrS = vtkDoubleArray.New();
            arrS.SetName("Sine");
            arrS.SetNumberOfComponents(1);
            arrS.SetNumberOfValues(numPoints);

            // Test charting with a few more points...
            double inc = 7.5 / (numPoints-1);
            for (long i = 0; i < numPoints; ++i)
            {
            arrX.SetValue(i, i * inc);
            arrC.SetValue(i, System.Math.Cos(i * inc) + 0.0);
            arrS.SetValue(i, System.Math.Sin(i * inc) + 0.0);
            }

            vtkTable table = vtkTable.New();
            table.AddColumn(arrX);
            table.AddColumn(arrC);
            table.AddColumn(arrS);

            // Add multiple line plots, setting the colors etc
            vtkPlot points = chart.AddPlot(0);
            points.SetInput(table, 0, 1);
            points.SetColor(0, 0, 0, 255);
            points.SetWidth((float)1.0);
            vtkPlotLine.SafeDownCast(points).SetMarkerStyle(4);
            points = chart.AddPlot(1);
            points.SetInput(table, 0, 2);
            points.SetColor(150, 0, 0, 255);
            points.SetWidth((float)2.0);
            vtkPlotPoints.SafeDownCast(points).SetMarkerStyle(3);

            // Add the actors to the renderer, set the window size
            //
            renWin.SetSize(250, 250);
            renWin.Render();
        }

On Feb 23, 2011, at 11:37 AM, dbenzhuser wrote:

> Hi everybody!
> 
> I'm searching for a kind of Activiz - RenderWindowControl - vtkChart "Hello World" example.
> 
> I was able to "rewrite" the chart example here
> http://www.kitware.com/products/html/NewChartAPIInVTK.html
> using the Activiz 5.6.1 framework, but I don't see how I can render a chart inside the Kitware.VTK.RenderWindowControl.
> 
> In the HalloVTKForm example provided with Activiz, a vtkActor is set with the AddViewProp() method, but I can't cast a ChartXY object to vtkProp (no wonder, they arent anywhere close in the object stucture).
> 
> I tried to create a new vtkContextView and set its render window to the one provided by the control like this:
> 
> vtkRenderWindow renwin = renderWindowControl1.RenderWindow;
> vtkContextView view = vtkContextView.New();
> (...)
> view.GetRenderer().SetRenderWindow(renwin);
> 
> but it only opens a new window instead of drawing inside the control.
> 
> Thanks for your help! _______________________________________________
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110223/278229b9/attachment.htm>


More information about the vtkusers mailing list