[vtkusers] How to extract a region using a box?
Polly Pui
polly_sukting at hotmail.com
Tue Aug 14 13:27:43 EDT 2018
Hi Kenichiro,
Thank you so much for your example!
I adjusted the values for the scale and translate and I could extract what I wanted.
Thanks! Have a nice day!
________________________________
From: kenichiro yoshimi <rccm.kyoshimi at gmail.com>
Sent: Tuesday, August 14, 2018 9:11 AM
To: polly_sukting at hotmail.com
Cc: vtkusers
Subject: Re: [vtkusers] How to extract a region using a box?
Hello Polly,
It may be helpful to get the bounds of the polydata by GetBounds()
method because vtkBox is defined with bounds. In the case that uses
fran_cut.vtk, there is something like below.
---
double bounds[6];
auto fran_cut = vtkPolyData::SafeDownCast(reader->GetOutput());
fran_cut->GetBounds(bounds);
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->PreMultiply();
transform->RotateZ(0.0);
transform->RotateY(0.0);
transform->RotateX(0.0);
transform->Scale(1, 0.4, 1);
transform->Translate(0, 0, 0);
vtkSmartPointer<vtkBox> box =
vtkSmartPointer<vtkBox>::New();
box->SetBounds(bounds);
box->SetTransform(transform);
---
Besides, if it is difficult for you to adjust the transform values
that you applied in ParaView, you might as well use Python scripting
in ParaView. In that case, you are more likely to get a better answer
if you post to the ParaView discussion forum:
https://discourse.paraview.org/
[https://discourse.paraview.org/uploads/default/original/1X/be27a23ecc6207834f74337e6527d80bcc475188.png]<https://discourse.paraview.org/>
ParaView<https://discourse.paraview.org/>
discourse.paraview.org
A place for questions about ParaView usage, building, and installation as well as general discussion about ParaView.
Thanks
2018年8月14日(火) 1:00 Polly Pui <polly_sukting at hotmail.com>:
>
>
> Hi,
> I tested using the values below with fran_cut.vtk but I failed to get the area.
> Please advice. Thank you so much!
>
> vtkSmartPointer<vtkTransform> transform =
> vtkSmartPointer<vtkTransform>::New();
> transform->PreMultiply();
> transform->RotateZ(0.0);
> transform->RotateY(0.0);
> transform->RotateX(0.0);
> transform->Translate(0.5, -10.0, -590.0);
> transform->Scale(0.5, 0.2, 0.6);
> vtkSmartPointer<vtkBox> box =
> vtkSmartPointer<vtkBox>::New();
> box->SetBounds(-1.0, 1.0, -1.0, 1.0, -0.6, 0.6);
> box->SetTransform(transform);
>
>
>
> ________________________________
> 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/20180814/43a927fc/attachment.html>
More information about the vtkusers
mailing list