[vtkusers] Understanding vtkAppendFilter ; interesting results..

Chiranjib Sur sur.chiranjib at gmail.com
Wed Aug 8 05:36:25 EDT 2018


Hi,
VTk cell information is missing when you are trying to merge (append) two
data sets

 vtkNew<vtkPoints> pts;
  for (int i = 0; i <= nx; ++i) {
    for (int j = 0; j <= ny; ++j) {
      for (int k = 0; k <= nz; ++k) {
        pts->InsertNextPoint(x1+dx*i, y1+dy*j, z1+dz*k);
      }
    }
  }


Here, if you create vtkCells (using the function InsertNextCell), following
the creation of vtk points,  then vtkAppend operation will work perfectly.

The definition of vtkAppendFilter has a description of the following :

vtkAppendFilter
<https://www.vtk.org/doc/nightly/html/classvtkAppendFilter.html> is a
filter that appends one of more datasets into a single unstructured grid.
All geometry is extracted and appended, but point attributes (i.e.,
scalars, vectors, normals, field data, etc.) are extracted and appended
only if all datasets have the point attributes available. (For example, if
one dataset has scalars but another does not, scalars will not be appended.)


You can have a look at the example file
https://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/Core/Testing/Cxx/TestAppendFilter.cxx

Hope this is helpful

Thanks and regards,
Chiranjib


On Tue, Aug 7, 2018 at 5:38 PM Fcs <ftpronk at engits.com> wrote:

> I'm trying to use vtkAppendFilter to merge different vtkStructuredGrid
> blocks
> together in one grid.
>
> I've tried two different approaches:
>  - Create the vtkStructuredGrid blocks, copy them to a vtkUnstructuredGrid,
> and call the AddInputData() method of vtkAppendFilter with that copied
> object.
>  - Create the vtkStructuredGrid blocks, store them in a vtkDataSet, and
> call
> the AddInputData() method with the vtkDataSet object.
>
> The first approach works (although, if possible, I would like to be able to
> aggregate the vtkStructuredGrid directly without the DeepCopy() trick..),
> and the second approach only partly works.
>
> The merged grids can be seen in my screenshots here below, which are from a
> plane slice at (-5, 0, 0) with normal (1, 0, 0). I'm using a 4 x 4 x 4 grid
> of blocks, with the centre blocks having twice the grid resolution of the
> outside blocks. Clearly something went wrong using vtkDataSet.
>
> Could somebody explain to me what went wrong, and why?  Or perhaps how I
> can
> best achieve what I'm trying to do?
>
> The code I used can be found after the screenshots.
>
> Thank you for the help.
>
> <
> http://vtk.1045678.n5.nabble.com/file/t342433/with_vtkUnstructuredGrid.png>
>
> <http://vtk.1045678.n5.nabble.com/file/t342433/with_vtkDataSet.png>
>
> #include <iostream>
> #include <vtkAppendFilter.h>
> #include <vtkNew.h>
> #include <vtkPoints.h>
> #include <vtkProperty.h>
> #include <vtkSmartPointer.h>
> #include <vtkStructuredGrid.h>
> #include <vtkUnstructuredGrid.h>
> #include <vtkUnstructuredGridWriter.h>
>
> vtkSmartPointer<vtkStructuredGrid> createGrid(int x1, int x2, int y1, int
> y2, int z1, int z2)
> {
>   int nx, ny, nz;
>   if (x1 > -20 && x2 < 20 &&
>       y1 > -20 && y2 < 20 &&
>       z1 > -20 && z2 < 20)
>   {
>     nx = ny = nz = 40;
>   } else {
>     nx = ny = nz = 20;
>   }
>   double dx, dy, dz;
>   dx = double(x2-x1)/nx;
>   dy = double(y2-y1)/ny;
>   dz = double(z2-z1)/nz;
>
>   vtkNew<vtkStructuredGrid> grid;
>   grid->SetDimensions(nx+1, ny+1, nz+1);
>
>   vtkNew<vtkPoints> pts;
>   for (int i = 0; i <= nx; ++i) {
>     for (int j = 0; j <= ny; ++j) {
>       for (int k = 0; k <= nz; ++k) {
>         pts->InsertNextPoint(x1+dx*i, y1+dy*j, z1+dz*k);
>       }
>     }
>   }
>   grid->SetPoints(pts.GetPointer());
>
>   return grid.GetPointer();
> }
>
> void mergeBlocks()
> {
>   vtkNew<vtkAppendFilter> filter;
>
>   for(int i = -20; i < 20; i += 10) {
>     for(int j = -20; j < 20; j += 10) {
>       for(int k = -20; k < 20; k += 10) {
>         vtkSmartPointer<vtkStructuredGrid>   sgrid = createGrid(i, i+10, j,
> j+10, k, k+10);
>         vtkSmartPointer<vtkUnstructuredGrid> ugrid =
> vtkSmartPointer<vtkUnstructuredGrid>::New();
>         ugrid->DeepCopy(sgrid);
>         filter->AddInputData(ugrid);
>         //vtkSmartPointer<vtkDataSet> data = createGrid(i, i+10, j, j+10,
> k,
> k+10);
>         //filter->AddInputData(data);
>       }
>     }
>   }
>   filter->Update();
>   std::cout << "Total number of cells:   " <<
> filter->GetOutput()->GetNumberOfCells() << std::endl;
>
>   vtkNew<vtkUnstructuredGridWriter> writer;
>   writer->SetFileName("output.vtk");
>   writer->SetInputData(filter->GetOutput());
>   writer->Write();
> }
>
> int main()
> {
>   mergeBlocks();
>
>   return EXIT_SUCCESS;
> }
>
>
> *If needed, here is the CMakeLists.txt file I used:
> *
>
> cmake_minimum_required(VERSION 2.8)
>
> PROJECT(CuttingTest)
>
> find_package(VTK REQUIRED)
> include(${VTK_USE_FILE})
>
> add_executable(cuttingTest cuttingtest.cxx )
>
> target_link_libraries(cuttingTest ${VTK_LIBRARIES})
>
>
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> 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:
> https://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180808/3f4cacad/attachment.html>


More information about the vtkusers mailing list