<div dir="ltr">Hi,<div>VTk cell information is missing when you are trying to merge (append) two data sets<div><br></div><div> vtkNew<vtkPoints> pts;<br>  for (int i = 0; i <= nx; ++i) {<br>    for (int j = 0; j <= ny; ++j) {<br>      for (int k = 0; k <= nz; ++k) {<br>        pts->InsertNextPoint(x1+dx*i, y1+dy*j, z1+dz*k);<br>      }<br>    }<br>  } </div><div> </div><div><br></div><div>Here, if you create vtkCells (using the function <span style="font-family:monospace;white-space:pre"><font color="#0000ff">InsertNextCell</font></span><span style="color:rgb(0,0,0);font-family:monospace;white-space:pre">)</span>, following the creation of vtk points,  then vtkAppend operation will work perfectly. </div><div><br></div><div>The definition of vtkAppendFilter has a description of the following :</div><div><font color="#0000ff"><br></font></div><div><font color="#0000ff" face="monospace, monospace"><a class="gmail-m_-2367709068859019989el" href="https://www.vtk.org/doc/nightly/html/classvtkAppendFilter.html" title="appends one or more datasets together into a single unstructured grid" style="font-weight:bold;font-size:14px" target="_blank">vtkAppendFilter</a><span style="font-size:14px"> 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.)</span> </font></div><div><br></div><div>You can have a look at the example file</div><div><a href="https://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/Core/Testing/Cxx/TestAppendFilter.cxx">https://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/Core/Testing/Cxx/TestAppendFilter.cxx</a><br></div><div><br></div><div>Hope this is helpful</div><div><div><div dir="ltr" class="gmail-m_-2367709068859019989gmail_signature"><div dir="ltr"><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Thanks and regards,</div><div style="font-size:12.8px">Chiranjib</div></div></div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Aug 7, 2018 at 5:38 PM Fcs <<a href="mailto:ftpronk@engits.com" target="_blank">ftpronk@engits.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm trying to use vtkAppendFilter to merge different vtkStructuredGrid blocks<br>
together in one grid.<br>
<br>
I've tried two different approaches:<br>
 - Create the vtkStructuredGrid blocks, copy them to a vtkUnstructuredGrid,<br>
and call the AddInputData() method of vtkAppendFilter with that copied<br>
object.<br>
 - Create the vtkStructuredGrid blocks, store them in a vtkDataSet, and call<br>
the AddInputData() method with the vtkDataSet object.<br>
<br>
The first approach works (although, if possible, I would like to be able to<br>
aggregate the vtkStructuredGrid directly without the DeepCopy() trick..),<br>
and the second approach only partly works.<br>
<br>
The merged grids can be seen in my screenshots here below, which are from a<br>
plane slice at (-5, 0, 0) with normal (1, 0, 0). I'm using a 4 x 4 x 4 grid<br>
of blocks, with the centre blocks having twice the grid resolution of the<br>
outside blocks. Clearly something went wrong using vtkDataSet.<br>
<br>
Could somebody explain to me what went wrong, and why?  Or perhaps how I can<br>
best achieve what I'm trying to do?<br>
<br>
The code I used can be found after the screenshots.<br>
<br>
Thank you for the help.<br>
<br>
<<a href="http://vtk.1045678.n5.nabble.com/file/t342433/with_vtkUnstructuredGrid.png" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/file/t342433/with_vtkUnstructuredGrid.png</a>> <br>
<<a href="http://vtk.1045678.n5.nabble.com/file/t342433/with_vtkDataSet.png" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/file/t342433/with_vtkDataSet.png</a>> <br>
<br>
#include <iostream><br>
#include <vtkAppendFilter.h><br>
#include <vtkNew.h><br>
#include <vtkPoints.h><br>
#include <vtkProperty.h><br>
#include <vtkSmartPointer.h><br>
#include <vtkStructuredGrid.h><br>
#include <vtkUnstructuredGrid.h><br>
#include <vtkUnstructuredGridWriter.h><br>
<br>
vtkSmartPointer<vtkStructuredGrid> createGrid(int x1, int x2, int y1, int<br>
y2, int z1, int z2)<br>
{<br>
  int nx, ny, nz;<br>
  if (x1 > -20 && x2 < 20 &&<br>
      y1 > -20 && y2 < 20 &&<br>
      z1 > -20 && z2 < 20)<br>
  {<br>
    nx = ny = nz = 40;<br>
  } else {<br>
    nx = ny = nz = 20;<br>
  }<br>
  double dx, dy, dz;<br>
  dx = double(x2-x1)/nx;<br>
  dy = double(y2-y1)/ny;<br>
  dz = double(z2-z1)/nz;<br>
<br>
  vtkNew<vtkStructuredGrid> grid;<br>
  grid->SetDimensions(nx+1, ny+1, nz+1);<br>
<br>
  vtkNew<vtkPoints> pts;<br>
  for (int i = 0; i <= nx; ++i) {<br>
    for (int j = 0; j <= ny; ++j) {<br>
      for (int k = 0; k <= nz; ++k) {<br>
        pts->InsertNextPoint(x1+dx*i, y1+dy*j, z1+dz*k);<br>
      }<br>
    }<br>
  }<br>
  grid->SetPoints(pts.GetPointer());<br>
<br>
  return grid.GetPointer();<br>
}<br>
<br>
void mergeBlocks()<br>
{<br>
  vtkNew<vtkAppendFilter> filter;<br>
<br>
  for(int i = -20; i < 20; i += 10) {<br>
    for(int j = -20; j < 20; j += 10) {<br>
      for(int k = -20; k < 20; k += 10) {<br>
        vtkSmartPointer<vtkStructuredGrid>   sgrid = createGrid(i, i+10, j,<br>
j+10, k, k+10);<br>
        vtkSmartPointer<vtkUnstructuredGrid> ugrid =<br>
vtkSmartPointer<vtkUnstructuredGrid>::New();<br>
        ugrid->DeepCopy(sgrid);<br>
        filter->AddInputData(ugrid);<br>
        //vtkSmartPointer<vtkDataSet> data = createGrid(i, i+10, j, j+10, k,<br>
k+10);<br>
        //filter->AddInputData(data);<br>
      }<br>
    }<br>
  }<br>
  filter->Update();<br>
  std::cout << "Total number of cells:   " <<<br>
filter->GetOutput()->GetNumberOfCells() << std::endl;<br>
<br>
  vtkNew<vtkUnstructuredGridWriter> writer;<br>
  writer->SetFileName("output.vtk");<br>
  writer->SetInputData(filter->GetOutput());<br>
  writer->Write();<br>
}<br>
<br>
int main()<br>
{<br>
  mergeBlocks();<br>
<br>
  return EXIT_SUCCESS;<br>
}<br>
<br>
<br>
*If needed, here is the CMakeLists.txt file I used:<br>
*<br>
<br>
cmake_minimum_required(VERSION 2.8)<br>
<br>
PROJECT(CuttingTest)<br>
<br>
find_package(VTK REQUIRED)<br>
include(${VTK_USE_FILE})<br>
<br>
add_executable(cuttingTest cuttingtest.cxx )<br>
<br>
target_link_libraries(cuttingTest ${VTK_LIBRARIES})<br>
<br>
<br>
<br>
<br>
<br>
--<br>
Sent from: <a href="http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html</a><br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">https://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</blockquote></div>