# vtkActor::SetUserMatrix make the vtkPolyData incorrect

**URL:** https://discourse.vtk.org/t/vtkactor-setusermatrix-make-the-vtkpolydata-incorrect/8417
**Category:** Support
**Created:** [May 3, 2022, 2:15pm UTC](https://discourse.vtk.org/t/vtkactor-setusermatrix-make-the-vtkpolydata-incorrect/8417 "2022-05-03T14:15:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [May 3, 2022, 2:15pm UTC](https://discourse.vtk.org/t/vtkactor-setusermatrix-make-the-vtkpolydata-incorrect/8417/1 "2022-05-03T14:15:31Z")

</div>

I am using `vtkContourFilter` in my application, and the result is correct:

![image](https://discourse.vtk.org/uploads/default/original/2X/3/354c1b18c80380703a1879be626bd549dd4d84fa.png)

Then, I use `vtkActor::SetUserMatrix` to correct the direction, and my code is:

```auto
	double ele[16] = {
		1, 0, 0, 0,
		0, -1, 0, 0,
		0, 0, 1, 0,
		0, 0, 0, 1
	};
	vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
	matrix->DeepCopy(ele);
	actor->SetUserMatrix(matrix);

```

Then, the result is incorrect:

![image](https://discourse.vtk.org/uploads/default/original/2X/d/d8918034027855c480754cfa0746f440a39cf254.png)

My complete code is:

```auto
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkDICOMImageReader.h"
#include "vtkSmartPointer.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkImageData.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkMatrix4x4.h"
void main()
{
	vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New();
	reader->SetDirectoryName(".\\TOF");
	reader->Update();

	vtkSmartPointer<vtkImageData> image = reader->GetOutput();

	vtkSmartPointer<vtkContourFilter> cf = vtkSmartPointer<vtkContourFilter>::New();
	cf->SetInputData(image);
	cf->UseScalarTreeOn();
	cf->ComputeNormalsOn();
	cf->SetValue(0, 500);
	cf->Update();

	vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
	mapper->SetInputData(cf->GetOutput());
	mapper->ScalarVisibilityOff();
	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(mapper);

	// -----------------the user matrix setting
	double ele[16] = {
		1, 0, 0, 0,
		0, -1, 0, 0,
		0, 0, 1, 0,
		0, 0, 0, 1
	};
	vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
	matrix->DeepCopy(ele);
	actor->SetUserMatrix(matrix);
	// -------------------

	vtkSmartPointer<vtkRenderer> render = vtkSmartPointer<vtkRenderer>::New();
	render->AddActor(actor);
	vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
	renWin->AddRenderer(render);
	renWin->Render();
	vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
	iren->SetRenderWindow(renWin);
	iren->Initialize();
	iren->SetInteractorStyle(vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New());
	iren->Start();
}

```

Any suggestion is appreciated~~~

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [May 3, 2022, 7:14pm UTC](https://discourse.vtk.org/t/vtkactor-setusermatrix-make-the-vtkpolydata-incorrect/8417/2 "2022-05-03T19:14:09Z")

</div>

The problem is that the matrix has a negative determinant:

```
double ele[16] = {
	1, 0, 0, 0,
	0, -1, 0, 0,
	0, 0, 1, 0,
	0, 0, 0, 1
};

```

Any transformation that generates a mirror-image of the data will also [reverse the orientation of the polygons](https://en.wikipedia.org/wiki/Curve_orientation), which causes the lighting calculations to fail. Hence, the rendering is black.

I’m not sure what outcome you are looking for, but I think you will get a better result if you either  
a) move the camera so that you are looking at the data from the opposite side, or  
b) flip the image before you apply vtkContourFilter
