[vtkusers] Uneven colors after the vtkButterflySubdivisionFilter

DivyaS div.anand141 at gmail.com
Sat Apr 20 13:39:29 EDT 2013


Sure, please check this code - I have removed all the unnecessary code. I
have added comments for each of the steps.

            //Defining a cylinder source.
            vtkCylinderSource cylinderSource = vtkCylinderSource.New();
            cylinderSource.Update();

            vtkTriangleFilter triangles = vtkTriangleFilter.New();
            triangles.SetInput(cylinderSource.GetOutput());
            triangles.Update();
            vtkPolyData originalMesh;
            originalMesh = triangles.GetOutput();

            vtkUnsignedCharArray colors = vtkUnsignedCharArray.New();
            colors.SetNumberOfComponents(3);
            colors.SetNumberOfTuples(originalMesh.GetNumberOfPolys());
            colors.SetName("Colors");

            //Creating an array to store the values according to which the
colors are selected.
            //Values are inserted for each of the points in the polydata
            int[] colorAT = new int[originalMesh.GetNumberOfPolys()];
            for (int i = 0; i < originalMesh.GetNumberOfPolys(); i++)
            {
                colorAT[i] = i;
            }

            int activationTime;
            //Loop to select colors for each of the points in the polydata.
            for (int i = 0; i < originalMesh.GetNumberOfPolys(); i++)
            {
                activationTime = colorAT[i];
                if (activationTime > 0 && activationTime < 5)
                {
                    //Black
                    colors.InsertTuple3(i, 255, 255, 0);
                }
                else if (activationTime > 4 && activationTime < 10)
                {
                    //Blue
                    colors.InsertTuple3(i, 0, 0, 255);
                }
                else if (activationTime > 9 && activationTime < 300)
                {
                    //Red
                    colors.InsertTuple3(i, 255, 0, 0);
                }
            }
            originalMesh.GetPointData().SetScalars(colors);

            //Subdivision.
            int numberOfSubdivisions = 4;
            vtkPolyDataAlgorithm subdivisionFilter =
vtkButterflySubdivisionFilter.New();
           
((vtkButterflySubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions);
            subdivisionFilter.SetInput(originalMesh);
            subdivisionFilter.Update();

            vtkRenderWindow renderWindow =
renderWindowControl1.RenderWindow;
            vtkRenderer renderer = vtkRenderer.New();
            
            //Create a mapper and actor
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
            mapper.SetInputConnection(subdivisionFilter.GetOutputPort());
            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);

            renderer.AddActor(actor);
            renderer.SetBackground(0, 0, 0);
            renderer.ResetCamera();
            renderWindow.AddRenderer(renderer);
            renderWindow.Render();



--
View this message in context: http://vtk.1045678.n5.nabble.com/Uneven-colors-after-the-vtkButterflySubdivisionFilter-tp5720205p5720234.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list