[vtkusers] How to extract a region using a box?

kenichiro yoshimi rccm.kyoshimi at gmail.com
Fri Aug 10 23:08:37 EDT 2018


Hi,

The Filter>Extract Cells By Region in ParaView uses vtkExtractGeometry
class internally. So the following example may be helpful to automate
polygon extractions with a specified box.

--- ExtractGeometry.cxx ---
#include <vtkBox.h>
#include <vtkCamera.h>
#include <vtkDataSetMapper.h>
#include <vtkExtractGeometry.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkTransform.h>

int main (int, char *[])
{
  vtkSmartPointer<vtkSphereSource> sphere =
    vtkSmartPointer<vtkSphereSource>::New();
  sphere->SetRadius(0.5);
  sphere->SetPhiResolution(50);
  sphere->SetThetaResolution(50);
  sphere->Update();

  vtkSmartPointer<vtkTransform> transform =
    vtkSmartPointer<vtkTransform>::New();
  transform->PreMultiply();
  transform->RotateZ(30.0);
  transform->Translate(0.5, 0.0, 0.0);

  vtkSmartPointer<vtkBox> box =
    vtkSmartPointer<vtkBox>::New();
  box->SetBounds(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5);
  box->SetTransform(transform);

  vtkSmartPointer<vtkExtractGeometry> extractGeometry =
    vtkSmartPointer<vtkExtractGeometry>::New();
  extractGeometry->SetInputData(sphere->GetOutput());
  extractGeometry->SetImplicitFunction(box);
  extractGeometry->ExtractInsideOn();
  extractGeometry->ExtractBoundaryCellsOn();

  vtkSmartPointer<vtkDataSetMapper> mapper =
    vtkSmartPointer<vtkDataSetMapper>::New();
  mapper->SetInputConnection(extractGeometry->GetOutputPort());

  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
  actor->GetProperty()->SetColor(0.8900, 0.8100, 0.3400);

  // Create graphics stuff
  //
  vtkSmartPointer<vtkRenderer> ren =
    vtkSmartPointer<vtkRenderer>::New();
  ren->SetBackground(.3, .4, .6);

  vtkSmartPointer<vtkRenderWindow> renWin =
    vtkSmartPointer<vtkRenderWindow>::New();
  renWin->AddRenderer(ren);
  renWin->SetSize(512,512);

  vtkSmartPointer<vtkRenderWindowInteractor> iren =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  iren->SetRenderWindow(renWin);

  // Add the actors to the renderer, set the background and size
  //
  ren->AddActor(actor);

  // Generate an interesting view
  //
  ren->ResetCamera();
  ren->GetActiveCamera()->Azimuth(120);
  ren->GetActiveCamera()->Elevation(30);
  ren->GetActiveCamera()->Dolly(1.0);
  ren->ResetCameraClippingRange();

  iren->Initialize();
  iren->Start();

  return EXIT_SUCCESS;
}

--- CMakeLists.txt ---
cmake_minimum_required(VERSION 2.8)

PROJECT(ExtractGeometry)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

add_executable(ExtractGeometry MACOSX_BUNDLE ExtractGeometry.cxx )

target_link_libraries(ExtractGeometry ${VTK_LIBRARIES})
---

Regards
2018年8月9日(木) 16:51 Polly Pui <polly_sukting at hotmail.com>:
>
> Hi,
>
> Can anyone please tell me how can I do extract a region by providing a box (which we can set the size of it) on a polydata?
>
> I could do it manually in Paraview by selecting the Filter>Extract Cells By Region.
>
> However, I have more than 1000 dataset. It is time consuming if I apply it manually for each dataset.
>
>
> Thanks!
>
>
> Best,
>
> Polly
>
> _______________________________________________
> 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


More information about the vtkusers mailing list