[vtkusers] WarpScalar - Problem about normal
Cory Quammen
cory.quammen at kitware.com
Mon Aug 31 09:27:14 EDT 2015
Does your VTP file have point Normals? Can you share the file?
Thanks,
Cory
On Mon, Aug 31, 2015 at 5:30 AM, lilymo <lilymagic2005 at yahoo.com.hk> wrote:
> By referencing the example of WarpScalar (
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/WarpScalar
> <http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/WarpScalar> ), I use a
> .vtp file instead of the sphere in the example, and I have edited some
> parts
> of it, mainly for the normal part.
>
> However, it seems that the point only offset towards the same normal, which
> results in a translation only.
>
> If I use vtkSphereSource, the following code can offset the points by its
> own normal, but not the same normal for all the points at the same time.
>
> What should I do? Thanks!
>
>
>
>
>
>
>
>
> #include <vtkActor.h>
> #include <vtkDoubleArray.h>
> #include <vtkPointData.h>
> #include <vtkPolyData.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkSmartPointer.h>
> #include <vtkSphereSource.h>
> #include <vtkWarpScalar.h>
> #include <vtkMath.h>
>
> #include <vtkXMLPolyDataReader.h>
>
> #include <vtkCylinderSource.h>
> #include <vtkUnsignedCharArray.h>
> #include <vtkTransform.h>
> #include <vtkTransformPolyDataFilter.h>
> #include <vtkProperty.h>
>
>
> int main(int, char *[])
> {
> vtkSmartPointer<vtkXMLPolyDataReader> sphereSource =
> vtkSmartPointer<vtkXMLPolyDataReader>::New();
> sphereSource->SetFileName("test.vtp");
>
> // Create Scalars
> vtkSmartPointer<vtkDoubleArray> scalars =
> vtkSmartPointer<vtkDoubleArray>::New();
> int numberOfPoints =
> sphereSource->GetOutput()->GetNumberOfPoints();
>
> sphereSource->GetOutput()->GetPointData()->SetScalars(scalars);
>
> vtkSmartPointer<vtkWarpScalar> warpScalar =
> vtkSmartPointer<vtkWarpScalar>::New();
> warpScalar->SetInputConnection(sphereSource->GetOutputPort());
> warpScalar->SetScaleFactor(1); // use the scalars themselves
>
> scalars->SetNumberOfTuples(numberOfPoints);
>
>
> for(vtkIdType i = 0; i < numberOfPoints; ++i)
> {
> scalars->SetTuple1(i,20);
> }
>
> //???
> warpScalar->GetUseNormal();
> warpScalar->Update();
>
>
>
> //--------------------------------------------------------------------
> vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> mapper->SetInputConnection(warpScalar->GetOutputPort());
>
> vtkSmartPointer<vtkActor> actor =
> vtkSmartPointer<vtkActor>::New();
> actor->GetProperty()->SetColor(1.0, 1.0, 0.0);
> actor->SetMapper(mapper);
>
> vtkSmartPointer<vtkPolyDataMapper> smapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> smapper->SetInputConnection(sphereSource->GetOutputPort());
>
> vtkSmartPointer<vtkActor> sactor =
> vtkSmartPointer<vtkActor>::New();
> sactor->GetProperty()->SetColor(1.0, 0.0, 1.0);
> sactor->SetMapper(smapper);
>
>
> //--------------------------------------------------------------------
> // Visualize
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
> vtkSmartPointer<vtkRenderWindow> renderWindow =
> vtkSmartPointer<vtkRenderWindow>::New();
> renderWindow->AddRenderer(renderer);
> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
> renderWindowInteractor->SetRenderWindow(renderWindow);
>
> renderer->AddActor(actor);
> renderer->AddActor(sactor);
> renderer->SetBackground(1,1,1);
>
> renderWindow->Render();
> renderWindowInteractor->Start();
>
> return EXIT_SUCCESS;
> }
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/WarpScalar-Problem-about-normal-tp5733689.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> 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:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
--
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150831/5a0c391d/attachment.html>
More information about the vtkusers
mailing list