# New class to modify vtkCutter

**URL:** <https://discourse.vtk.org/t/new-class-to-modify-vtkcutter/4801>\
**Category:** Development\
**Created:** [December 11, 2020, 7:22am UTC](https://discourse.vtk.org/t/new-class-to-modify-vtkcutter/4801 "2020-12-11T07:22:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sugeng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sugeng/32/2026_2.png) [@sugeng](https://discourse.vtk.org/u/sugeng)\
**Post date:** [December 11, 2020, 7:22am UTC](https://discourse.vtk.org/t/new-class-to-modify-vtkcutter/4801/1 "2020-12-11T07:22:31Z")

</div>

Dear All,

I have a new class designed to modify output from vtkCutter as shown below. Here, this class must be placed directly after vtkCutter.

This new class had been actually written before in VTK 4.2 which worked properly. However, after some modifications to follow the latest VTK version here, the class cannot read the data from vtkCutter properly (although the overall pipeline itself still works to visualize the dataset).

If you all do not mind, I would like to ask your help regarding this problem.

Thanks a lot .  
Warm regards,  
Sugeng

* * *

**Header file** :

#ifndef \_vtkModCut\_test\_h  
#define \_vtkModCut\_test\_h

#include “vtkCutter.h”  
#include “vtkFiltersCoreModule.h”  
#include “vtkPolyDataAlgorithm.h”

#include  
#include

class vtkModCut\_test:public vtkPolyDataAlgorithm  
{  
public:  
static vtkModCut\_test \*New();  
void PrintSelf(ostream &os, vtkIndent indent);  
void Execute();  
vtkIdType sourceId;

protected:  
vtkModCut\_test();  
~vtkModCut\_test();

private :  
vtkModCut\_test(const vtkModCut\_test&); // Not implemented  
void operator=(const vtkModCut\_test&); // Not implemented  
};

* * *

**The class:**

#include  
#include  
#include  
#include

#include “vtkSetGet.h”  
#include “vtkModCut\_test.h”  
#include “vtkObject.h”  
#include “vtkObjectFactory.h”  
#include “vtkIndent.h”  
#include “vtkDataArray.h”  
#include “vtkMath.h”  
#include “vtkDataSet.h”  
#include “vtkPointData.h”  
#include “vtkCellData.h”  
#include “vtkPlane.h”  
#include “vtkContourValues.h”  
#include “vtkPolyData.h”  
#include “vtkDoubleArray.h”  
#include “vtkFloatArray.h”  
#include “vtkPolygon.h”  
#include “vtkPoints.h”  
#include “vtkPointDataToCellData.h”  
#include “vtkCell.h”  
#include “vtkDataSetAttributes.h”  
#include “vtkLookupTable.h”  
#include “vtkDataObject.h”  
#include “vtkInformation.h”  
#include “vtkInformationVector.h”

#include “vtkSmartPointer.h”

// create object in VTK (instead of using common constructor and destructor in C++)  
vtkStandardNewMacro(vtkModCut\_test);

vtkModCut\_test::vtkModCut\_test()  
{  
}

vtkModCut\_test::~vtkModCut\_test()  
{  
}

//Printself definition (??)  
void vtkModCut\_test::PrintSelf(ostream& os, vtkIndent indent)  
{  
//not implemented yet  
}

void vtkModCut\_test::Execute()  
{  
double tnsor[3][3],t\_n[3];  
double n\_stress, s\_stress[3];  
double n[3];  
double \*\*A,\*count;  
vtkPoints \*pts;

```
vtkDataSet *dset = nullptr ;
vtkDataSet *input = nullptr;
vtkDataArray *stressTensors;
vtkIdType numPts=input->GetNumberOfPoints(); 
vtkIdType numCells=input->GetNumberOfCells();	
vtkIdType ptId,ptId1,ptId2,ptId3;
vtkIdType cellId;
vtkPolyData *output=this->GetOutput();
vtkDoubleArray* newScalars= vtkDoubleArray::New();
vtkDoubleArray* newVectors= vtkDoubleArray::New();
vtkCell *cell;

output->CopyStructure(input);

stressTensors = dset->GetPointData()->GetTensors();
vtkIdType n_tensor = stressTensors->GetNumberOfTuples();

A = new double*[numPts];
count = new double[numPts];
for(ptId=0;ptId<numPts;ptId++)
{
	A[ptId]=new double[3];
}

for(ptId=0;ptId<numPts;ptId++)
{
	count[ptId] = 0.0f;
	for (int j=0;j<3;j++)
	{
		A[ptId][j] = 0.0f;
	}
}

for (cellId = 0; cellId < numCells; ++cellId)
{
	cell=input->GetCell(cellId);
	ptId1=cell->GetPointId(0);
	ptId2=cell->GetPointId(1);
	ptId3=cell->GetPointId(2);
	
	pts=cell->GetPoints();
	vtkPolygon::ComputeNormal(pts, n);

	for (int j=0;j<3;j++)
	{
	A[ptId1][j] = A[ptId1][j]+n[j];
	A[ptId2][j] = A[ptId2][j]+n[j];
	A[ptId3][j] = A[ptId3][j]+n[j];
	
	}
	
	count[ptId1] = count[ptId1]+1.0f;
	count[ptId2] = count[ptId2]+1.0f;
	count[ptId3] = count[ptId3]+1.0f;
}

for (ptId=0; ptId < numPts ; ptId++)
{           
	for(int j=0; j<3;j++)
	{
		n[j] = -A[ptId][j]/count[ptId];
	}

	double* sig = stressTensors->GetTuple9(ptId); //get point data attribute (tensor/tuple 9 component)

	// get tensor component
	tnsor[0][0] = sig[0];
	tnsor[0][1] = sig[1];
	tnsor[0][2] = sig[2];
	tnsor[1][0] = sig[3];
	tnsor[1][1] = sig[4];
	tnsor[1][2] = sig[5];
	tnsor[2][0] = sig[6];
	tnsor[2][1] = sig[7];
	tnsor[2][2] = sig[8];

	vtkMath::Multiply3x3(tnsor,n,t_n);   

	n_stress=vtkMath::Dot(n,t_n);

	s_stress[0]=t_n[0]-n[0]*n_stress;
	s_stress[1]=t_n[1]-n[1]*n_stress;
	s_stress[2]=t_n[2]-n[2]*n_stress;

	double a=s_stress[0];
	double b=s_stress[1];
	double c=s_stress[2];
	
	newScalars->InsertTuple1(ptId,n_stress);
	
	newVectors->SetNumberOfComponents(3);
	newVectors->InsertTuple3(ptId,a,b,c);
}

newScalars->SetName("Normal");
newVectors->SetName("Shear");
output->GetPointData()->AddArray(newScalars);
output->GetPointData()->AddArray(newVectors);
output->GetPointData()->SetActiveScalars("Normal");
output->GetPointData()->SetActiveVectors("Shear");

for(ptId=0;ptId<numPts;ptId++)
{
	delete[] A[ptId];
}
	
delete[] A;
delete[] count;
newScalars->Delete();
newVectors->Delete();

```

}

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [December 12, 2020, 3:56am UTC](https://discourse.vtk.org/t/new-class-to-modify-vtkcutter/4801/2 "2020-12-12T03:56:09Z")

</div>

I would recommend to find a similar filter in current VTK version and replace the processing part with yours. You may also be able to use/start from [vtkvmtkMeshWallShearRate class in VMTK](https://github.com/vmtk/vmtk/blob/ef598dea844e0190eee99490b333c13452c81f6d/vtkVmtk/Misc/vtkvmtkMeshWallShearRate.cxx).
