# vtkPlaneSources as faces for vtkCubeSource

**URL:** https://discourse.vtk.org/t/vtkplanesources-as-faces-for-vtkcubesource/15532
**Category:** vtk.js
**Tags:** vtkjs
**Created:** [April 22, 2025, 2:06pm UTC](https://discourse.vtk.org/t/vtkplanesources-as-faces-for-vtkcubesource/15532 "2025-04-22T14:06:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [April 22, 2025, 2:06pm UTC](https://discourse.vtk.org/t/vtkplanesources-as-faces-for-vtkcubesource/15532/1 "2025-04-22T14:06:31Z")

</div>

Hello

I want to streamline a plane source in each of the faces of a cube source. The objective is to have a rectangular grid which I can use to paint some scalars. I need control on the resolution, but in theory each axis keeps the same resolution (same resolution for all xs, same for all ys, etc). Also, the cube source controls the dimensions.

This is probably too complicated and there is an easier way to achieve, but I can’t think of any other easy way to do it than manually decimate the cube source itself. This last option does not preserve the axis resolution and does not preserve the rectangular grid.

At the end, I expect a polydata with painted faces (A cube with scalars in its surface with a defined resolution per axis) to be displayed in my js scene. Obviously the scalars will vary with some interactions, therefore, generating several polygons is not optimal.

Is there some easier way to achieve this?

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [April 24, 2025, 2:14pm UTC](https://discourse.vtk.org/t/vtkplanesources-as-faces-for-vtkcubesource/15532/2 "2025-04-24T14:14:54Z")

</div>

Adding more, I have tried so far the following

```auto
function buildTestModelSource()
    {
        let appendPolyData = vtkAppendPolyData.newInstance();
        const dimensions = [30, 30, 20]; // cm
        const translation = [0, 0, -20]; // translation to patient model center

        // Plane -Z
        const PlaneZ1Data = {
            xResolution: 300,
            yResolution: 300,
            origin: [-dimensions[0] / 2 + translation[0], -dimensions[1] / 2 + translation[1], -dimensions[2] / 2 + translation[2]],
            point1: [dimensions[0] / 2 + translation[0], -dimensions[1] / 2 + translation[1], -dimensions[2] / 2 + translation[2]],
            point2: [-dimensions[0] / 2 + translation[0], dimensions[1] / 2 + translation[1], -dimensions[2] / 2 + translation[2]],
            pointType: 'Float64Array'
        };
        let PlaneZ1 = vtkPlaneSource.newInstance(PlaneZ1Data);
        appendPolyData.addInputData(PlaneZ1.getOutputData());

        // Plane +Z
        const PlaneZ2Data = {
            xResolution: 300,
            yResolution: 300,
            origin: [-dimensions[0] / 2 + translation[0], -dimensions[1] / 2 + translation[1], dimensions[2] / 2 + translation[2]],
            point1: [-dimensions[0] / 2 + translation[0], dimensions[1] / 2 + translation[1], dimensions[2] / 2 + translation[2]],
            point2: [dimensions[0] / 2 + translation[0], -dimensions[1] / 2 + translation[1], dimensions[2] / 2 + translation[2]],
            pointType: 'Float64Array'
        };
        let PlaneZ2 = vtkPlaneSource.newInstance(PlaneZ2Data);
        appendPolyData.addInputData(PlaneZ2.getOutputData());

        // Plane -X
        const PlaneX1Data = {
            xResolution: 200,
            yResolution: 300,
            origin: [-dimensions[0] / 2 + translation[0], -dimensions[1] / 2 + translation[1], -dimensions[2] / 2 + translation[2]],
            point1: [-dimensions[0] / 2 + translation[0], dimensions[1] / 2 + translation[1], -dimensions[2] / 2 + translation[2]],
            point2: [-dimensions[0] / 2 + translation[0], -dimensions[1] / 2 + translation[1], dimensions[2] / 2 + translation[2]],
            pointType: 'Float64Array'
        };
        let PlaneX1 = vtkPlaneSource.newInstance(PlaneX1Data);
        appendPolyData.addInputData(PlaneX1.getOutputData());

        // Plane +X
        const PlaneX2Data = {
            xResolution: 200,
            yResolution: 300,
            origin: [dimensions[0] / 2 + translation[0], -dimensions[1] / 2 + translation[1], -dimensions[2] / 2 + translation[2]],
            point1: [dimensions[0] / 2 + translation[0], -dimensions[1] / 2 + translation[1], dimensions[2] / 2 + translation[2]],
            point2: [dimensions[0] / 2 + translation[0], dimensions[1] / 2 + translation[1], -dimensions[2] / 2 + translation[2]],
            pointType: 'Float64Array'
        };
        let PlaneX2 = vtkPlaneSource.newInstance(PlaneX2Data);
        appendPolyData.addInputData(PlaneX2.getOutputData());

        // Planes -Y and +Y are not used
        appendPolyData.setOutputPointsPrecision(0);
        return appendPolyData.getOutputData();
    }

```

Which draws the Box, but it does not allow me to draw the scalars as it doesn’t define the polys (cells).  
I get `Uncaught TypeError: Cannot read properties of undefined (reading 'getCellType')`

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [April 25, 2025, 2:27pm UTC](https://discourse.vtk.org/t/vtkplanesources-as-faces-for-vtkcubesource/15532/3 "2025-04-25T14:27:11Z")

</div>

I have to pass it through a filter to get the proper polydata

```auto
let smoother = vtk.Filters.Core.vtkPolyDataNormals.newInstance();
let model = buildTestModelSource();
model.buildCells();
model.buildLinks();
smoother.setInputData(model);
mapper.setInputConnection(smoother.getOutputPort());

```

And now it works. Really hard for something that should be easy.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/0/02ff424089496f32129615b0ab85c0eed744ebc8.png)
