New class to modify vtkCutter

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();

}

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.