# [vtkusers] Regularly sample 3D unstructured tensor grid

Jochen Jankowai jochen.jankowai at gmail.com
Tue Nov 28 09:23:01 EST 2017

Hi,
The resulting structured grid has 0 values at all positions though.
Am I forgetting to specify that/how I want to interpolate the tensors or something like that?

See code below:

auto bounds = unstructuredGrid->GetBounds();

// Create a grid of points to interpolate over
auto gridSize = ivec3(32);
const auto gridBounds = dvec3(31);
vtkSmartPointer<vtkPoints> gridPoints = vtkSmartPointer<vtkPoints>::New();

const auto xRange = std::abs(bounds[0] - bounds[1]);
const auto yRange = std::abs(bounds[2] - bounds[3]);
const auto zRange = std::abs(bounds[4] - bounds[5]);

const auto stepSize = dvec3(xRange / gridBounds.x, yRange / gridBounds.y, zRange / gridBounds.z);

for (int x = 0; x < gridSize.x; x++) {
for (int y = 0; y < gridSize.y; y++) {
for (int z = 0; z < gridSize.z; z++) {
const auto xCoord = bounds[0] + static_cast<double>(x) * stepSize.x;
const auto yCoord = bounds[2] + static_cast<double>(y) * stepSize.y;
const auto zCoord = bounds[4] + static_cast<double>(z) * stepSize.z;
gridPoints->InsertNextPoint(xCoord, yCoord, zCoord);
}
}
}

// Create a dataset from the grid points
vtkSmartPointer<vtkStructuredGrid> pointSet =
vtkSmartPointer<vtkStructuredGrid>::New();
pointSet->SetDimensions(glm::value_ptr(gridSize));
pointSet->SetPoints(gridPoints);

vtkSmartPointer<vtkProbeFilter> probeFilter =
vtkSmartPointer<vtkProbeFilter>::New();
probeFilter->SetSourceData(unstructuredGrid);

probeFilter->SetInputData(pointSet);

probeFilter->Update();

auto structuredGrid = probeFilter->GetStructuredGridOutput();

auto pointData = structuredGrid->GetPointData();
auto tensors = pointData->GetArray("strain_0.0");

-----Original Message-----
From: kenichiro yoshimi [mailto:rccm.kyoshimi at gmail.com]
Sent: den 25 november 2017 04:50
To: PetiteViking <jochen.jankowai at gmail.com>
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] Regularly sample 3D unstructured tensor grid

Hi,

The standard way of retrieving PointData is not  auto tensors = pointData->GetArray(); but  auto tensors = pointData->GetArray(0);  auto tensors = pointData->GetArray("array-name");
auto tensors = pointData->GetTensors("array-name");

vtkPointData inherits from vtkDataSetAttributes and
pointData->GetArray() is trying to access the FieldData which
describes global properties of pointData, but it is null.

Thanks

2017-11-24 21:48 GMT+09:00 PetiteViking <jochen.jankowai at gmail.com>:
> Hello everyone! I've tried to find an answer to my problem in the
> forum for quite some time now but I cannot seem to find a solution. I
> have an unstructured hexahedral grid that stores one tensor per cell.
> What I need in my application though is a regulargrid so I would like
> to regularly sample the field. So far, this is what I am trying to
> (see code below). In one of the posts here I have read that
> vtkProbeFilter will produce output that corresponds to the input so I
> amusing a structured grid as input for which I have computed points.
> And while I manage to retreive a structured grid from the probeFilter,
> the variable tensors ends up being a nullptr. auto reader =
> grid of points to interpolate over auto gridSize = glm::ivec3(32, 32,
> 32); vtkSmartPointer<vtkPoints> gridPoints =
> vtkSmartPointer<vtkPoints>::New();
> for (int x = 0; x < gridSize.x; x++) {  for (int y = 0; y <
> gridSize.y; y++) {   for (int z = 0; z < gridSize.z; z++) {
> gridPoints->InsertNextPoint(x, y, z);   }  } } // Create a dataset
> from the grid points vtkSmartPointer<vtkStructuredGrid> pointSet =
>  vtkSmartPointer<vtkStructuredGrid>::New();
> pointSet->SetDimensions(glm::value_ptr(gridSize));
> pointSet->SetPoints(gridPoints); vtkSmartPointer<vtkProbeFilter>
> pointSet->probeFilter
> =  vtkSmartPointer<vtkProbeFilter>::New();
> probeFilter->SetSourceData(unstructuredGrid);
> probeFilter->SetInputData(pointSet); probeFilter->Update(); auto
> structuredGrid = probeFilter->GetStructuredGridOutput(); auto
> pointData =
> structuredGrid->GetPointData(); auto tensors =
> structuredGrid->GetPointData()->GetTensors();
> ________________________________
> Sent from the VTK - Users mailing list archive at Nabble.com.
>
> _______________________________________________
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>