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

Polly Pui polly_sukting at hotmail.com
Mon Aug 13 11:54:47 EDT 2018


Thanks Kenichiro! This is what i am looking for.
I could run your example smoothly. However, I tried to run with my data and adjusted the transform values that i applied in Paraview, there was nothing extracted.
I tried with a larger scale but it happened to be the same.
My dataset is frontal and centre with origin.
Is there anything that i have to adjust to get the extracted area?

Polly

________________________________
From: kenichiro yoshimi <rccm.kyoshimi at gmail.com>
Sent: Saturday, August 11, 2018 11:08 AM
To: polly_sukting at hotmail.com
Cc: vtkusers
Subject: Re: [vtkusers] How to extract a region using a box?

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<http://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/20180813/d0b48226/attachment.html>


More information about the vtkusers mailing list