<div dir="ltr">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).<div><br></div><div>If you do indeed want to warp by surface normals, there is a filter you can use to generate these.</div><div><br></div><div><pre class="" style="font-family:monospace,monospace;padding:0px;border:0px none white;color:rgb(0,0,0);line-height:1.2em;font-stretch:normal;font-size:1em;margin-top:0px;margin-bottom:0px;vertical-align:top;background:none rgb(249,249,249)">    vtkSmartPointer<span class="" style="color:rgb(0,0,128)"><</span>vtkPolyDataNormals<span class="" style="color:rgb(0,0,128)">></span> normalGenerator <span class="" style="color:rgb(0,0,128)">=</span> vtkSmartPointer<span class="" style="color:rgb(0,0,128)"><</span>vtkPolyDataNormals<span class="" style="color:rgb(0,0,128)">></span><span class="" style="color:rgb(0,128,128)">::</span><span class="" style="color:rgb(0,119,136)">New</span><span class="" style="color:rgb(0,128,0)">(</span><span class="" style="color:rgb(0,128,0)">)</span><span class="" style="color:rgb(0,128,128)">;</span>
    normalGenerator<span class="" style="color:rgb(0,0,64)">-</span><span class="" style="color:rgb(0,0,128)">></span>SetInputData<span class="" style="color:rgb(0,128,0)">(</span>polydata<span class="" style="color:rgb(0,128,0)">)</span><span class="" style="color:rgb(0,128,128)">;</span>
    normalGenerator<span class="" style="color:rgb(0,0,64)">-</span><span class="" style="color:rgb(0,0,128)">></span>ComputePointNormalsOn<span class="" style="color:rgb(0,128,0)">(</span><span class="" style="color:rgb(0,128,0)">)</span><span class="" style="color:rgb(0,128,128)">;</span>
    normalGenerator<span class="" style="color:rgb(0,0,64)">-</span><span class="" style="color:rgb(0,0,128)">></span>ComputeCellNormalsOff<span class="" style="color:rgb(0,128,0)">(</span><span class="" style="color:rgb(0,128,0)">)</span><span class="" style="color:rgb(0,128,128)">;</span>
    normalGenerator<span class="" style="color:rgb(0,0,64)">-</span><span class="" style="color:rgb(0,0,128)">></span>Update<span class="" style="color:rgb(0,128,0)">(</span><span class="" style="color:rgb(0,128,0)">)</span><span class="" style="color:rgb(0,128,128)">;</span></pre><pre class="" style="font-family:monospace,monospace;padding:0px;border:0px none white;color:rgb(0,0,0);line-height:1.2em;font-stretch:normal;font-size:1em;margin-top:0px;margin-bottom:0px;vertical-align:top;background:none rgb(249,249,249)"><span class="" style="color:rgb(0,128,128)"><br></span></pre><div>This snippet is derived from [1].</div><div><br></div>Connect the output of this filter to your vtkWarpScalar object and you should get warping behavior that matches what happens with the sphere source.</div><div><br></div><div>HTH,</div><div>Cory</div><div><br></div><div>[1] <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataExtractNormals">http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataExtractNormals</a><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 31, 2015 at 10:59 PM, lilymo <span dir="ltr"><<a href="mailto:lilymagic2005@yahoo.com.hk" target="_blank">lilymagic2005@yahoo.com.hk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I ve got a new version of the code, as I debugged the code that the old<br>
version didn't get a valid number of points of the polydata.<br>
<br>
#include <vtkVersion.h><br>
#include <vtkCellData.h><br>
#include <vtkDoubleArray.h><br>
#include <vtkFloatArray.h><br>
#include <vtkPoints.h><br>
#include <vtkPolyData.h><br>
#include <vtkPolyDataNormals.h><br>
#include <vtkPointData.h><br>
#include <vtkSmartPointer.h><br>
#include <vtkSphereSource.h><br>
#include <vtkXMLPolyDataReader.h><br>
<br>
#include <vtkWarpScalar.h><br>
#include <vtkPolyDataMapper.h><br>
#include <vtkActor.h><br>
#include <vtkRenderWindowInteractor.h><br>
#include <vtkRenderer.h><br>
#include <vtkRenderWindow.h><br>
#include <vtkProperty.h><br>
void TestPointNormals(vtkPolyData* polydata);<br>
void TestCellNormals(vtkPolyData* polydata);<br>
<br>
bool GetPointNormals(vtkPolyData* polydata);<br>
bool GetCellNormals(vtkPolyData* polydata);<br>
<br>
int main(int argc, char *argv[])<br>
{<br>
        vtkSmartPointer<vtkPolyData> polydata =<br>
vtkSmartPointer<vtkPolyData>::New();<br>
        vtkSmartPointer<vtkXMLPolyDataReader> reader =<br>
vtkSmartPointer<vtkXMLPolyDataReader>::New();<br>
        reader->SetFileName("model.vtp");<br>
        reader->Update();<br>
        polydata->DeepCopy(reader->GetOutput());<br>
<br>
        std::cout << "PolyData address: " << polydata << std::endl;<br>
        std::cout << "In TestPointNormals: " << polydata->GetNumberOfPoints() <<<br>
std::endl;<br>
<span class=""><br>
        vtkSmartPointer<vtkDoubleArray> scalars =<br>
                vtkSmartPointer<vtkDoubleArray>::New();<br>
<br>
</span>        reader->GetOutput()->GetPointData()->SetScalars(scalars);<br>
<span class=""><br>
        vtkSmartPointer<vtkWarpScalar> warpScalar =<br>
                vtkSmartPointer<vtkWarpScalar>::New();<br>
</span>        warpScalar->SetInputConnection(reader->GetOutputPort());<br>
<span class="">        warpScalar->SetScaleFactor(1); // use the scalars themselves<br>
<br>
</span>        int numOfPoints = polydata->GetNumberOfPoints();<br>
<br>
        scalars->SetNumberOfTuples(numOfPoints);<br>
<br>
        for(vtkIdType i = 0; i < (polydata->GetNumberOfPoints()); ++i)<br>
        {<br>
                scalars->SetTuple1(i,200);<br>
        }<br>
<br>
        //warpScalar->GetUseNormal();<br>
        warpScalar->Update();<br>
<br>
        // Create a mapper and actor<br>
<span class="">        vtkSmartPointer<vtkPolyDataMapper> mapper =<br>
                vtkSmartPointer<vtkPolyDataMapper>::New();<br>
        mapper->SetInputConnection(warpScalar->GetOutputPort());<br>
<br>
        vtkSmartPointer<vtkActor> actor =<br>
                vtkSmartPointer<vtkActor>::New();<br>
        actor->GetProperty()->SetColor(1.0, 1.0, 0.0);<br>
        actor->SetMapper(mapper);<br>
<br>
</span>        // Create a mapper and actor<br>
<span class="">        vtkSmartPointer<vtkPolyDataMapper> smapper =<br>
                vtkSmartPointer<vtkPolyDataMapper>::New();<br>
</span>        smapper->SetInputConnection(reader->GetOutputPort());<br>
<span class=""><br>
        vtkSmartPointer<vtkActor> sactor =<br>
                vtkSmartPointer<vtkActor>::New();<br>
        sactor->GetProperty()->SetColor(1.0, 0.0, 1.0);<br>
        sactor->SetMapper(smapper);<br>
<br>
<br>
</span><span class="">        // Visualize<br>
        vtkSmartPointer<vtkRenderer> renderer =<br>
                vtkSmartPointer<vtkRenderer>::New();<br>
        vtkSmartPointer<vtkRenderWindow> renderWindow =<br>
                vtkSmartPointer<vtkRenderWindow>::New();<br>
        renderWindow->AddRenderer(renderer);<br>
        vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =<br>
                vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
        renderWindowInteractor->SetRenderWindow(renderWindow);<br>
<br>
        renderer->AddActor(actor);<br>
        renderer->AddActor(sactor);<br>
<br>
</span>        renderer->SetBackground(1,1,1); // Background color white<br>
<span class=""><br>
        renderWindow->Render();<br>
        renderWindowInteractor->Start();<br>
        return EXIT_SUCCESS;<br>
}<br>
<br>
<br>
<br>
<br>
</span>--<br>
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/WarpScalar-Problem-about-normal-tp5733689p5733700.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/WarpScalar-Problem-about-normal-tp5733689p5733700.html</a><br>
<div class="HOEnZb"><div class="h5">Sent from the VTK - Users mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Cory Quammen<br>R&D Engineer<br>Kitware, Inc.</div>
</div>