[vtkusers] WarpScalar - Problem about normal

Cory Quammen cory.quammen at kitware.com
Tue Sep 1 13:35:20 EDT 2015


As I suspected, your VTP file does not have a vector array that can be used
to determine the direction of the warp. In your code, you are generating a
scalar array specifying the magnitude of the vector displacement, but you
are not generating the vector array that specifies the direction of
displacement. You need to compute the surface normals (assuming you want to
warp the geometry according to the surface normals).

If you do indeed want to warp by surface normals, there is a filter you can
use to generate these.

    vtkSmartPointer<vtkPolyDataNormals> normalGenerator =
vtkSmartPointer<vtkPolyDataNormals>::New();
    normalGenerator->SetInputData(polydata);
    normalGenerator->ComputePointNormalsOn();
    normalGenerator->ComputeCellNormalsOff();
    normalGenerator->Update();


This snippet is derived from [1].

Connect the output of this filter to your vtkWarpScalar object and you
should get warping behavior that matches what happens with the sphere
source.

HTH,
Cory

[1] http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataExtractNormals



On Mon, Aug 31, 2015 at 10:59 PM, lilymo <lilymagic2005 at yahoo.com.hk> wrote:

> I ve got a new version of the code, as I debugged the code that the old
> version didn't get a valid number of points of the polydata.
>
> #include <vtkVersion.h>
> #include <vtkCellData.h>
> #include <vtkDoubleArray.h>
> #include <vtkFloatArray.h>
> #include <vtkPoints.h>
> #include <vtkPolyData.h>
> #include <vtkPolyDataNormals.h>
> #include <vtkPointData.h>
> #include <vtkSmartPointer.h>
> #include <vtkSphereSource.h>
> #include <vtkXMLPolyDataReader.h>
>
> #include <vtkWarpScalar.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkActor.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindow.h>
> #include <vtkProperty.h>
> void TestPointNormals(vtkPolyData* polydata);
> void TestCellNormals(vtkPolyData* polydata);
>
> bool GetPointNormals(vtkPolyData* polydata);
> bool GetCellNormals(vtkPolyData* polydata);
>
> int main(int argc, char *argv[])
> {
>         vtkSmartPointer<vtkPolyData> polydata =
> vtkSmartPointer<vtkPolyData>::New();
>         vtkSmartPointer<vtkXMLPolyDataReader> reader =
> vtkSmartPointer<vtkXMLPolyDataReader>::New();
>         reader->SetFileName("model.vtp");
>         reader->Update();
>         polydata->DeepCopy(reader->GetOutput());
>
>         std::cout << "PolyData address: " << polydata << std::endl;
>         std::cout << "In TestPointNormals: " <<
> polydata->GetNumberOfPoints() <<
> std::endl;
>
>         vtkSmartPointer<vtkDoubleArray> scalars =
>                 vtkSmartPointer<vtkDoubleArray>::New();
>
>         reader->GetOutput()->GetPointData()->SetScalars(scalars);
>
>         vtkSmartPointer<vtkWarpScalar> warpScalar =
>                 vtkSmartPointer<vtkWarpScalar>::New();
>         warpScalar->SetInputConnection(reader->GetOutputPort());
>         warpScalar->SetScaleFactor(1); // use the scalars themselves
>
>         int numOfPoints = polydata->GetNumberOfPoints();
>
>         scalars->SetNumberOfTuples(numOfPoints);
>
>         for(vtkIdType i = 0; i < (polydata->GetNumberOfPoints()); ++i)
>         {
>                 scalars->SetTuple1(i,200);
>         }
>
>         //warpScalar->GetUseNormal();
>         warpScalar->Update();
>
>         // Create a mapper and actor
>         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);
>
>         // Create a mapper and actor
>         vtkSmartPointer<vtkPolyDataMapper> smapper =
>                 vtkSmartPointer<vtkPolyDataMapper>::New();
>         smapper->SetInputConnection(reader->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); // Background color white
>
>         renderWindow->Render();
>         renderWindowInteractor->Start();
>         return EXIT_SUCCESS;
> }
>
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/WarpScalar-Problem-about-normal-tp5733689p5733700.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/20150901/068b38b1/attachment.html>


More information about the vtkusers mailing list