[vtkusers] Regularly sample 3D unstructured tensor grid

kenichiro yoshimi rccm.kyoshimi at gmail.com
Tue Nov 28 20:46:00 EST 2017


Hello,

The reason why resampling fails cannot be found, but at least, the order of
IJK-coordinates of the structured points is needed to be changed in reverse.

for (int z = 0; z < gridSize.z; z++) {
  for (int y = 0; y < gridSize.y; y++) {
    for (int x = 0; x < gridSize.x; x++) {
     ...

Also I attached a sample that works.
Hope that helps to solve.

2017-11-28 23:23 GMT+09:00 Jochen Jankowai <jochen.jankowai at gmail.com>:

> Hi,
> Thank you for your reply! I have adjusted my code according to your
> suggestions which had the effect that I am not getting a nullptr any longer.
> 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 reader = vtkUnstructuredGridReader::New();
>
>     reader->SetFileName(file_.get().c_str());
>
>     reader->SetReadAllTensors(1);
>
>     reader->Update();
>
>     auto unstructuredGrid = reader->GetOutput();
>
>     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 =
> > vtkUnstructuredGridReader::New();
> > reader->SetFileName(file_.get().c_str());
> > reader->Update(); auto unstructuredGrid = reader->GetOutput(); //
> > reader->Create a
> > 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.
> >
> > _______________________________________________
> > Powered by www.kitware.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
> >
> > Follow this link to subscribe/unsubscribe:
> > http://public.kitware.com/mailman/listinfo/vtkusers
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171129/c6a29109/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: StructuredGrid.tar.gz
Type: application/x-gzip
Size: 15620 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171129/c6a29109/attachment.bin>


More information about the vtkusers mailing list