# How to select and color specific cells of a RGrid?

**URL:** https://discourse.vtk.org/t/how-to-select-and-color-specific-cells-of-a-rgrid/1792
**Category:** Support
**Created:** [September 20, 2019, 10:30am UTC](https://discourse.vtk.org/t/how-to-select-and-color-specific-cells-of-a-rgrid/1792 "2019-09-20T10:30:14Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Mikend994](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@Mikend994](https://discourse.vtk.org/u/Mikend994)
#### Post date: [September 20, 2019, 10:30am UTC](https://discourse.vtk.org/t/how-to-select-and-color-specific-cells-of-a-rgrid/1792/1 "2019-09-20T10:30:14Z")

</div>

Hi, I’m really new in vtk. I need to defining a path inside the RGrid example, by coloring a certain number of specific cells. This is the code

#include \<vtkActor.h\>  
#include \<vtkCamera.h\>  
#include \<vtkFloatArray.h\>  
#include \<vtkNamedColors.h\>  
#include \<vtkNew.h\>  
#include \<vtkPolyDataMapper.h\>  
#include \<vtkProperty.h\>  
#include \<vtkRectilinearGrid.h\>  
#include \<vtkRectilinearGridGeometryFilter.h\>  
#include \<vtkRenderWindow.h\>  
#include \<vtkRenderWindowInteractor.h\>  
#include \<vtkRenderer.h\>

#include

int main()  
{  
vtkNew colors;

std::array\<int, 16\> x = {  
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};  
std::array\<int, 16\> y = {  
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} };  
std::array\<int, 16\> z = {  
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};

// Create a rectilinear grid by defining three arrays specifying the  
// coordinates in the x-y-z directions.  
vtkNew xCoords;  
for (auto&& i : x)  
{  
xCoords-\>InsertNextValue(i);  
}  
vtkNew yCoords;  
for (auto&& i : y)  
{  
yCoords-\>InsertNextValue(i);  
}  
vtkNew zCoords;  
for (auto&& i : z)  
{  
zCoords-\>InsertNextValue(i);  
}

// The coordinates are assigned to the rectilinear grid. Make sure that  
// the number of values in each of the XCoordinates, YCoordinates,  
// and ZCoordinates is equal to what is defined in SetDimensions().  
//  
vtkNew rgrid;  
rgrid-\>SetDimensions(int(x.size()), int(y.size()), int(z.size()));  
rgrid-\>SetXCoordinates(xCoords);  
rgrid-\>SetYCoordinates(yCoords);  
rgrid-\>SetZCoordinates(zCoords);

// Extract a plane from the grid to see what we’ve got.  
vtkNew plane;  
plane-\>SetInputData(rgrid);  
plane-\>SetExtent(0, 46, 16, 16, 0, 43);

vtkNew rgridMapper;  
rgridMapper-\>SetInputConnection(plane-\>GetOutputPort());

vtkNew wireActor;  
wireActor-\>SetMapper(rgridMapper);  
wireActor-\>GetProperty()-\>SetRepresentationToWireframe();  
wireActor-\>GetProperty()-\>SetColor(colors-\>GetColor3d(“Black”).GetData());

// Create the usual rendering stuff.  
vtkNew renderer;  
vtkNew renWin;  
renWin-\>AddRenderer(renderer);  
vtkNew iren;  
iren-\>SetRenderWindow(renWin);

renderer-\>AddActor(wireActor);  
renderer-\>SetBackground(1, 1, 1);  
renderer-\>ResetCamera();  
renderer-\>GetActiveCamera()-\>Elevation(30.0);  
renderer-\>GetActiveCamera()-\>Azimuth(15.0);  
renderer-\>GetActiveCamera()-\>Zoom(1.0);  
renderer-\>SetBackground(colors-\>GetColor3d(“Beige”).GetData());

renWin-\>SetSize(600, 600);

// interact with data  
renWin-\>Render();  
iren-\>Start();

return EXIT\_SUCCESS;  
}

How can I do it?
