[vtkusers] Understanding vtkAppendFilter ; interesting results..
Fcs
ftpronk at engits.com
Tue Aug 7 08:08:09 EDT 2018
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
More information about the vtkusers
mailing list