How to change the points in a polydata

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to change the points in a polydata

舞法舞天
Hello.
       I read a ply file and want to change its' points' postion, but the code below doesn't work , how can i do?
      vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName("d:\\plane.ply");
reader->Update();
vtkPolyData* data = reader->GetOutput();
int n = data->GetNumberOfPoints();
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->DeepCopy(data->GetPoints());
for (int i = 0; i < n; i++)
{
double *p = points->GetPoint(i);
p[2] = 0;
}
       vtkSmartPointer<vtkSimplePointsWriter>writer = vtkSmartPointer<vtkSimplePointsWriter>::New();
writer->SetInputData(data);
writer->SetFileName("d:\\abc.txt");
writer->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(data);
mapper->Update();
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
//actor->GetProperty()->SetRepresentationToWireframe();
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
vtkSmartPointer<vtkRenderWindow> window =
vtkSmartPointer<vtkRenderWindow>::New();
window->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(window);



_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: How to change the points in a polydata

kenichiro yoshimi
Hi 舞法舞天,

If written as follows, this will work well.
---
  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
  points->ShallowCopy(data->GetPoints());
  for (int i = 0; i < n; i++)
  {
    double *p = points->GetPoint(i);
    p[2] = 0;
    points->SetPoint(i, p);
  }
---

Best
2018年7月14日(土) 15:41 舞法舞天 <[hidden email]>:

>
> Hello.
>        I read a ply file and want to change its' points' postion, but the code below doesn't work , how can i do?
>       vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
> reader->SetFileName("d:\\plane.ply");
> reader->Update();
> vtkPolyData* data = reader->GetOutput();
> int n = data->GetNumberOfPoints();
> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
> points->DeepCopy(data->GetPoints());
> for (int i = 0; i < n; i++)
> {
> double *p = points->GetPoint(i);
> p[2] = 0;
> }
>        vtkSmartPointer<vtkSimplePointsWriter>writer = vtkSmartPointer<vtkSimplePointsWriter>::New();
> writer->SetInputData(data);
> writer->SetFileName("d:\\abc.txt");
> writer->Update();
> vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> mapper->SetInputData(data);
> mapper->Update();
> vtkSmartPointer<vtkActor> actor =
> vtkSmartPointer<vtkActor>::New();
> actor->SetMapper(mapper);
> //actor->GetProperty()->SetRepresentationToWireframe();
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
> renderer->AddActor(actor);
> vtkSmartPointer<vtkRenderWindow> window =
> vtkSmartPointer<vtkRenderWindow>::New();
> window->AddRenderer(renderer);
> vtkSmartPointer<vtkRenderWindowInteractor> interactor =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
> interactor->SetRenderWindow(window);
>
>
> _______________________________________________
> 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
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

回复: How to change the points in a polydata

舞法舞天
This works well thanks


------------------ 原始邮件 ------------------
发件人: "kenichiro yoshimi"<[hidden email]>;
发送时间: 2018年7月14日(星期六) 晚上7:19
收件人: "舞法舞天"<[hidden email]>;
抄送: "vtkusers"<[hidden email]>;
主题: Re: [vtkusers] How to change the points in a polydata

Hi 舞法舞天,

If written as follows, this will work well.
---
  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
  points->ShallowCopy(data->GetPoints());
  for (int i = 0; i < n; i++)
  {
    double *p = points->GetPoint(i);
    p[2] = 0;
    points->SetPoint(i, p);
  }
---

Best
2018年7月14日(土) 15:41 舞法舞天 <[hidden email]>:

>
> Hello.
>        I read a ply file and want to change its' points' postion, but the code below doesn't work , how can i do?
>       vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
> reader->SetFileName("d:\\plane.ply");
> reader->Update();
> vtkPolyData* data = reader->GetOutput();
> int n = data->GetNumberOfPoints();
> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
> points->DeepCopy(data->GetPoints());
> for (int i = 0; i < n; i++)
> {
> double *p = points->GetPoint(i);
> p[2] = 0;
> }
>        vtkSmartPointer<vtkSimplePointsWriter>writer = vtkSmartPointer<vtkSimplePointsWriter>::New();
> writer->SetInputData(data);
> writer->SetFileName("d:\\abc.txt");
> writer->Update();
> vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> mapper->SetInputData(data);
> mapper->Update();
> vtkSmartPointer<vtkActor> actor =
> vtkSmartPointer<vtkActor>::New();
> actor->SetMapper(mapper);
> //actor->GetProperty()->SetRepresentationToWireframe();
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
> renderer->AddActor(actor);
> vtkSmartPointer<vtkRenderWindow> window =
> vtkSmartPointer<vtkRenderWindow>::New();
> window->AddRenderer(renderer);
> vtkSmartPointer<vtkRenderWindowInteractor> interactor =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
> interactor->SetRenderWindow(window);
>
>
> _______________________________________________
> 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

_______________________________________________
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