# Colors of vtkAnnotatedCubeActor faces (with vtkOrientationMarkerWidget)

**URL:** https://discourse.vtk.org/t/colors-of-vtkannotatedcubeactor-faces-with-vtkorientationmarkerwidget/934
**Category:** Support
**Created:** [May 9, 2019, 7:49am UTC](https://discourse.vtk.org/t/colors-of-vtkannotatedcubeactor-faces-with-vtkorientationmarkerwidget/934 "2019-05-09T07:49:25Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Marco](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco/32/1461_2.png) [@Marco](https://discourse.vtk.org/u/Marco)
#### Post date: [May 9, 2019, 7:49am UTC](https://discourse.vtk.org/t/colors-of-vtkannotatedcubeactor-faces-with-vtkorientationmarkerwidget/934/1 "2019-05-09T07:49:25Z")

</div>

Hi all.  
In my VTK 3D scene, I am using a vtkOrientationMarkerWidget which in turn uses a vtkAnnotatedCubeActor as the widget’s vtkProp.

I have an apparently-trivial question: how to customize the colors of this cube’s faces?

I am easily able to customize the texts appearing on each cube’s face, but I could not find an easy way to customize faces colors.

Any hint?

Thanks in advance and best regards,

Marco Sambin

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [May 10, 2019, 9:55am UTC](https://discourse.vtk.org/t/colors-of-vtkannotatedcubeactor-faces-with-vtkorientationmarkerwidget/934/2 "2019-05-10T09:55:09Z")

</div>

This example may help [AnatomicalOrientation](https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/AnatomicalOrientation/). Actually it may not help as only the text color is changed.

---

<div class="post-metadata">

### Author: ![Marco](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco/32/1461_2.png) [@Marco](https://discourse.vtk.org/u/Marco)
#### Post date: [May 10, 2019, 10:28am UTC](https://discourse.vtk.org/t/colors-of-vtkannotatedcubeactor-faces-with-vtkorientationmarkerwidget/934/3 "2019-05-10T10:28:22Z")

</div>

Hi Andrew,

thanks for taking the time to share this example with me.

Actually, as you guessed in your message, I was already able to change the text color. What I would like to achieve is changing the color of the “faces” of the cube, and I didn’t find an easy way to do this.

What I imagined to do was to associate cell data to the cube source, and then maybe apply a LUT on cell data on the mapper. In addition to being complex, this doesn’t even seem to be possible, as the cubeSource is not accessible on my vtkAnnotatedCubeActor instance…  
Moreover, setting this LUT on my mapper could even have other side-effects…

Anything simpler?

Any further hint would be greatly appreciated.  
Best regards,

Marco Sambin

---

<div class="post-metadata">

### Author: ![figueiredo](https://discourse.vtk.org/user_avatar/discourse.vtk.org/figueiredo/32/304_2.png) [@figueiredo](https://discourse.vtk.org/u/figueiredo)
#### Post date: [May 14, 2019, 7:39am UTC](https://discourse.vtk.org/t/colors-of-vtkannotatedcubeactor-faces-with-vtkorientationmarkerwidget/934/4 "2019-05-14T07:39:11Z")

</div>

Hi Marco!

The best solution I could think of is to compose the letters from the `vtkAnnotatedCubeActor` with a basic cube actor of the same size with colored faces. In order to do that, you should:

1. _Hide_ the annotated cube faces by setting it’s opacity property to `0`
2. Create an array to hold the six colors for the faces
3. Create a actor based on the `vtkCubeSource` setting its CellData Scalars to use the color array
4. _Merge_ the `vtkAnnotatedCubeActor` and colored actor using `vtkPropAssembly`
5. Use the `vtkPropAssembly` output as your marker for the `vtkOrientationMarkerWidget`

I tried to simplify the coloring part, to avoid difficulties for you to choose what colors go in what faces:

```auto
  vtkSmartPointer<vtkUnsignedCharArray> face_colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
  face_colors->SetNumberOfComponents(3);
  unsigned char face_x_plus[3] = { 255,0,0 };
  unsigned char face_x_minus[3] = { 0,255,0 };
  unsigned char face_y_plus[3] = { 0,0,255 };
  unsigned char face_y_minus[3] = { 255,255,0 };
  unsigned char face_z_plus[3] = { 0,255,255 };
  unsigned char face_z_minus[3] = { 255,0,255 };
  face_colors->InsertNextTypedTuple(face_x_minus);
  face_colors->InsertNextTypedTuple(face_x_plus);
  face_colors->InsertNextTypedTuple(face_y_minus);
  face_colors->InsertNextTypedTuple(face_y_plus);
  face_colors->InsertNextTypedTuple(face_z_minus);
  face_colors->InsertNextTypedTuple(face_z_plus);

```

Anyways, follow attached the modified example I made to test it. [main.cpp](https://discourse.vtk.org/uploads/default/original/1X/5c76b2bfcf82184e6b26092cde947216a47f511a.cpp) (4.6 KB)

 ![image](https://discourse.vtk.org/uploads/default/original/1X/5482d5cf222626cccebcbda47500dcdf6778fa13.png)

Hope this is useful.  
Have a fruitful week!

Rodrigo Figueiredo.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [May 14, 2019, 10:41pm UTC](https://discourse.vtk.org/t/colors-of-vtkannotatedcubeactor-faces-with-vtkorientationmarkerwidget/934/5 "2019-05-14T22:41:21Z")

</div>

That is a really nice approach and very ingenious. Would you like to contribute it to VTKExamples? I would be glad to help or add it for you.

---

<div class="post-metadata">

### Author: ![Marco](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco/32/1461_2.png) [@Marco](https://discourse.vtk.org/u/Marco)
#### Post date: [May 15, 2019, 9:36am UTC](https://discourse.vtk.org/t/colors-of-vtkannotatedcubeactor-faces-with-vtkorientationmarkerwidget/934/6 "2019-05-15T09:36:06Z")

</div>

Dear Rodrigo,

I would like to really thank you very much for taking the time to provide such a complete reply to my post: your suggestion is very smart, and it works indeed!

For those working with Java (like me), I would just like to mention that some of the methods that you used on vtkUnsignedCharArray are not available, hence here is the Java equivalent of that portion:

======

```
  vtkCubeSource cubeSource = new vtkCubeSource();
  cubeSource.Update();
  
  vtkUnsignedCharArray faceColors = new vtkUnsignedCharArray();
  faceColors.SetNumberOfComponents(3);
  faceColors.InsertNextTuple3(255, 0, 0);
  faceColors.InsertNextTuple3(255, 0, 0);
  faceColors.InsertNextTuple3(0, 255, 0);
  faceColors.InsertNextTuple3(0, 255, 0);
  faceColors.InsertNextTuple3(0, 0, 255);
  faceColors.InsertNextTuple3(0, 0, 255);
  
  cubeSource.GetOutput().GetCellData().SetScalars(faceColors);
  cubeSource.Update();
  
  vtkPolyDataMapper cubeMapper = new vtkPolyDataMapper();
  cubeMapper.SetInputData(cubeSource.GetOutput());
  cubeMapper.Update();
  
  vtkActor cubeActor = new vtkActor();
  cubeActor.SetMapper(cubeMapper);
  
  vtkPropAssembly propAssembly = new vtkPropAssembly();
  propAssembly.AddPart(orientMarkerCubeProp);
  propAssembly.AddPart(cubeActor);

```

======

Once again, thanks a lot, you solved my problem man!

Best regards,

Marco Sambin

---

<div class="post-metadata">

### Author: ![figueiredo](https://discourse.vtk.org/user_avatar/discourse.vtk.org/figueiredo/32/304_2.png) [@figueiredo](https://discourse.vtk.org/u/figueiredo)
#### Post date: [May 15, 2019, 3:52pm UTC](https://discourse.vtk.org/t/colors-of-vtkannotatedcubeactor-faces-with-vtkorientationmarkerwidget/934/7 "2019-05-15T15:52:08Z")

</div>

Thanks!  
If you consider that this would be a useful contribution, I would be interested in seeing how you did it afterwards, since I don’t know how to do it.

And @Marco, I’m glad it helped 😉

All the best,  
Rodrigo Figueiredo.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [May 15, 2019, 10:11pm UTC](https://discourse.vtk.org/t/colors-of-vtkannotatedcubeactor-faces-with-vtkorientationmarkerwidget/934/8 "2019-05-15T22:11:08Z")

</div>

@figueiredo I’ll do a C++ and Python version for the VTK Examples.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [May 18, 2019, 10:34pm UTC](https://discourse.vtk.org/t/colors-of-vtkannotatedcubeactor-faces-with-vtkorientationmarkerwidget/934/9 "2019-05-18T22:34:22Z")

</div>

The examples are here [(C++)](https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/ColoredAnnotatedCube/) and here [(Python)](https://lorensen.github.io/VTKExamples/site/Python/VisualizationAlgorithms/ColoredAnnotatedCube/).

Thanks once again @figueiredo for the idea.
