I am working on displaying a vectorfield. The 3-components vector data is set as point-data in a vtkRectilinearGrid. This is, how I implemented the cutting:
vtkCutter* planeCut = vtkCutter::New();|
planeCut->SetInputData(grid);|
planeCut->SetCutFunction(plane);|
planeCut->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::VECTORS);|
planeCut->Update();|
auto test = planeCut->GetOutput();|
I set the plane origin within the grid coordinates, but what I observe in the output data is that all PointData in vtkDataSet and vtkPolyData have a value of something e +66, which is totally unexpected.
Could someone please confirm if my use of the vtkCutter is correct as it is ?
Let me share a dummy setup to illustrate my issue:
//Settup grid
vtkRectilinearGrid* grid = vtkRectilinearGrid::New();
vtkNew<vtkDoubleArray> xCoo, yCoo, zCoo;
int numberOfNodesPerDimension = 13;
int numberOfNodesTotal = std::pow(numberOfNodesPerDimension, 3);
for (int i = 0; i < numberOfNodesPerDimension; i++)
{
xCoo->InsertNextValue(i);
yCoo->InsertNextValue(i);
zCoo->InsertNextValue(i);
}
grid->SetXCoordinates(xCoo);
grid->SetXCoordinates(yCoo);
grid->SetXCoordinates(zCoo);
vtkNew<vtkDoubleArray> vectorData;
vectorData->SetNumberOfComponents(3);
vectorData->SetNumberOfTuples(numberOfNodesTotal);
for (int i = 0; i < numberOfNodesTotal; i++)
{
int value = 13;
vectorData->SetTuple3(i, value, value, value);
}
auto temp = grid->GetPointData()->SetVectors(vectorData);
grid->GetPointData()->Update();
//Cutting data set
vtkNew<vtkPlane> plane;
plane->SetNormal(0, 1, 0);
plane->SetOrigin(1, 1, 1);
vtkNew<vtkCutter> cutter;
cutter->SetInputData(grid);
cutter->SetCutFunction(plane);
cutter->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::VECTORS);
cutter->Update();
auto temp = cutter->GetOutput();
vtkNew<vtkVectorNorm> norm;
norm->SetInputConnection(cutter->GetOutputPort());
norm->Update();
double* range = norm->GetOutput()->GetScalarRange();
The euclidien norm of the inserted vectors is 22.5 but what I get as a range is 0 to 1. I tried to look into the result of the cutter via the temp varaible, but I can’t find any data array in the depth of the vtk output object.
Thus, extending my question from above, I would like to know if there is a possibility to debug the output of the vtkCutter, since I don’t get the expected outcome from the following filter.
Kind regards,
Jan
Update:
I solved the issue. Firstly the fixed dummy:
vtkRectilinearGrid* grid = vtkRectilinearGrid::New();
vtkNew<vtkDoubleArray> xCoo, yCoo, zCoo;
int numberOfNodesPerDimension = 13;
int numberOfNodesTotal = std::pow(numberOfNodesPerDimension, 3);
grid->SetDimensions(numberOfNodesPerDimension, numberOfNodesPerDimension, numberOfNodesPerDimension);
int answ = xCoo->Resize(numberOfNodesPerDimension);
answ = yCoo->Resize(numberOfNodesPerDimension);
answ = zCoo->Resize(numberOfNodesPerDimension);
for (int i = 0; i < numberOfNodesPerDimension; i++)
{
xCoo->InsertNextValue(i);
yCoo->InsertNextValue(i);
zCoo->InsertNextValue(i);
}
grid->SetXCoordinates(xCoo);
grid->SetYCoordinates(yCoo);
grid->SetZCoordinates(zCoo);
vtkNew<vtkDoubleArray> vectorData;
vectorData->SetNumberOfComponents(3);
vectorData->SetNumberOfTuples(numberOfNodesTotal);
for (int i = 0; i < numberOfNodesTotal; i++)
{
int value = 13;
vectorData->SetTuple3(i, value, value, value);
}
grid->GetPointData()->SetVectors(vectorData);
grid->GetPointData()->Update();
auto temp = grid->GetPointData()->GetVectors();
//Cutting data set
vtkNew<vtkPlane> plane;
plane->SetNormal(0, 1, 0);
double minOffset = (grid->GetXCoordinates()->GetTuple1(1) - grid->GetXCoordinates()->GetTuple1(0)) / 1000;
double x = grid->GetXCoordinates()->GetTuple1(0) + minOffset;
double y = grid->GetYCoordinates()->GetTuple1(0) + minOffset;
double z = grid->GetZCoordinates()->GetTuple1(0) + minOffset;
plane->SetOrigin(x,y, z);
vtkCutter* cutter = vtkCutter::New();
cutter->SetInputData(grid);
cutter->SetCutFunction(plane);
cutter->Update();
auto cutterTemp = cutter->GetOutput()->GetPointData()->GetVectors();
vtkNew<vtkVectorNorm> norm;
norm->SetInputConnection(cutter->GetOutputPort());
norm->NormalizeOff();
norm->Update();
double* range = norm->GetOutput()->GetScalarRange();
The observed value with some e +66 is the result when a cut is made outside the data set. It is strange that the vtkCutter cannot perform a cut at the lowest coordinate. This also leads to the strange values mentioned above. On the other hand, the maximum coordinate works fine.
I solved the problem by adding a relative offset to the minimum coordinate.