<div dir="ltr">Hi Elena,<div><br></div><div>You code worked fine when</div><div><br></div><div> - vtkFloatArray is used to down cast (on win32)</div><div> - the input has normals. (as Bill asked)</div><div><br></div><div>I reproduced your bug when the input dataset didn't have normals... insert a vtkPolyDataNormals filter into your code to check this out.</div>
<div><br></div><div>Goodwin</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 8, 2014 at 2:12 PM, Bill Lorensen <span dir="ltr"><<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Are you certain that the input file has Normals?</p><div class="HOEnZb"><div class="h5">
<div class="gmail_quote">On Apr 8, 2014 8:33 AM, "elena bresciani" <<a href="mailto:elena.bresciani87@gmail.com" target="_blank">elena.bresciani87@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Here it is, I omitted the inclusion of the header files and the output section<br><div><br><br><br>int main ( int argc, char *argv[] )<br>{<br> <i><br></i> std::string filename = argv[1];<br> <br>
// Read data from the file<br>
vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();<br> reader->SetFileName(filename.c_str());<br> reader->Update();<br> <br> // polydata object<br>
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();<br><br> // get normals<br> vtkDoubleArray *pointNormalsArray = vtkDoubleArray::SafeDownCast (polydata->GetPointData()->GetNormals());<br>
<br> <br> vtkSmartPointer<vtkPolyData> newpolydata = vtkSmartPointer<vtkPolyData>::New();<br> vtkSmartPointer<vtkPoints> newPoints = vtkSmartPointer<vtkPoints>::New();<br><br> // for every point p1 in the polydata find the point p2 which lies on the normal at a distance D from p1 <br>
<br> for(vtkIdType i = 0; i < pointNormalsArray->GetNumberOfTuples(); i++) <br> <br> {<br> double p1[3];<br> polydata->GetPoint(i,p1); //prendo il punto <br> <br>
double pN[3]; <br> pointNormalsArray->GetTuple(i, pN);<br> <br> double p2[3];<br> double D=2*atoi(argv[3]); <br> p2[0]=p1[0]-pN[0]*D;<br> p2[1]=p1[1]-pN[1]*D;<br>
p2[2]=p1[2]-pN[2]*D;<br> <br><br> vtkIdType pid[1];<br> pid[0]=newPoints->InsertNextPoint(p2); <br> <br> }<br> <br> //set points to polydata<br>
newpolydata->SetPoints(newPoints);<br> <br> return EXIT_SUCCESS;<br>}<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-08 13:58 GMT+02:00 Bill Lorensen <span dir="ltr"><<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Please post a small, complete, compilable example that illustrates your problem.<br>
<div><div><br>
On Tue, Apr 8, 2014 at 3:19 AM, elena bresciani<br>
<<a href="mailto:elena.bresciani87@gmail.com" target="_blank">elena.bresciani87@gmail.com</a>> wrote:<br>
> Thank you guys,<br>
><br>
> I tried changing the type of PointNormalArray in vtkDoubleArray<br>
><br>
> vtkDoubleArray *PointNormalArray = vtkDoubleArray::SafeDownCast(<br>
> polydata->GetPointData()->GetNormals() ) ;<br>
><br>
> but I still have the segfault.<br>
><br>
> Elena<br>
><br>
><br>
> 2014-04-07 19:31 GMT+02:00 Goodwin Lawlor <<a href="mailto:goodwin.lawlor.lists@gmail.com" target="_blank">goodwin.lawlor.lists@gmail.com</a>>:<br>
><br>
>> Thanks for that link Shawn and setting me straight (I did day I could be<br>
>> wrong ;-))<br>
>><br>
>> My logic was that if you had to do:<br>
>><br>
>> vtkSmartPointer<vtkPolyData> polydata =<br>
>> vtkSmartPointer<vtkPolyData>::New();<br>
>><br>
>> then initializing a smart pointer not created with the form on the RHS<br>
>> above wouldn't work...<br>
>><br>
>> Goodwin<br>
>><br>
>><br>
>> On Mon, Apr 7, 2014 at 6:17 PM, Shawn Waldon <<a href="mailto:swaldon@cs.unc.edu" target="_blank">swaldon@cs.unc.edu</a>> wrote:<br>
>>><br>
>>> Hi Goodwin,<br>
>>><br>
>>> It shouldn't be causing the segfault. That line will create a new smart<br>
>>> pointer and set its internal pointer to the reader's output, incrementing<br>
>>> the reference count.<br>
>>> See<br>
>>> <a href="http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers#Getting_an_Object_with_a_Smart_Pointer" target="_blank">http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers#Getting_an_Object_with_a_Smart_Pointer</a><br>
>>> for details. If the reference increment is unnecessary, then it is still<br>
>>> only a small performance gain and not a segfault causing bug.<br>
>>><br>
>>> My guess for the segfault is what Bill said: the normals are in a<br>
>>> vtkDoubleArray not a vtkFloatArray so SafeDownCast is returning NULL.<br>
>>><br>
>>> HTH,<br>
>>><br>
>>> Shawn<br>
>>><br>
>>><br>
>>> On Mon, Apr 7, 2014 at 1:11 PM, Goodwin Lawlor<br>
>>> <<a href="mailto:goodwin.lawlor.lists@gmail.com" target="_blank">goodwin.lawlor.lists@gmail.com</a>> wrote:<br>
>>>><br>
>>>> Hi Elena,<br>
>>>><br>
>>>> I coud be wrong but I dont think this is correct:<br>
>>>><br>
>>>>> vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();<br>
>>>><br>
>>>><br>
>>>> reader->GetOutput() returns a regular pointer to a vtkPolydata not a<br>
>>>> smart pointer.<br>
>>>><br>
>>>> Try:<br>
>>>><br>
>>>> vtkPolyData *polydata = reader->GetOutput();<br>
>>>><br>
>>>> instead.<br>
>>>><br>
>>>> hth<br>
>>>><br>
>>>> Goodwin<br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>> On Mon, Apr 7, 2014 at 4:00 PM, elena bresciani<br>
>>>> <<a href="mailto:elena.bresciani87@gmail.com" target="_blank">elena.bresciani87@gmail.com</a>> wrote:<br>
>>>>><br>
>>>>> Hello everybody!<br>
>>>>><br>
>>>>> I need your help with a segmentation fault error.<br>
>>>>> Using gdb I understood where it is generated but I don't know how to<br>
>>>>> modify the code to make it run.<br>
>>>>><br>
>>>>> Here's the portion of the code that I'm talking about:<br>
>>>>><br>
>>>>><br>
>>>>> vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();<br>
>>>>> (the reader is a vtkXMLPolyDataReader)<br>
>>>>><br>
>>>>> vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(<br>
>>>>> polydata->GetPointData()->GetNormals() ) ;<br>
>>>>><br>
>>>>> for(vtkIdType i = 0; i < PointNormalArray->GetNumberOfTuples(); i++)<br>
>>>>> {....}<br>
>>>>><br>
>>>>> everytime I call GetNumberOfTuples I have this error so I think the<br>
>>>>> problem is on PointNormalArray.<br>
>>>>><br>
>>>>> Can somebody help me?<br>
>>>>><br>
>>>>> Thanks in advance<br>
>>>>><br>
>>>>> Elena<br>
>>>>><br>
>>>>> _______________________________________________<br>
>>>>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>>>>><br>
>>>>> Visit other Kitware open-source projects at<br>
>>>>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>>>>><br>
>>>>> Please keep messages on-topic and check the VTK FAQ at:<br>
>>>>> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>>>>><br>
>>>>> Follow this link to subscribe/unsubscribe:<br>
>>>>> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
>>>>><br>
>>>><br>
>>>><br>
>>>> _______________________________________________<br>
>>>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>>>><br>
>>>> Visit other Kitware open-source projects at<br>
>>>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>>>><br>
>>>> Please keep messages on-topic and check the VTK FAQ at:<br>
>>>> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>>>><br>
>>>> Follow this link to subscribe/unsubscribe:<br>
>>>> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
>>>><br>
>>><br>
>>><br>
>>><br>
>>> --<br>
>>> Shawn Waldon<br>
>>> Graduate Research Assistant<br>
>>> Department of Computer Science<br>
>>> University of North Carolina at Chapel Hill<br>
>>> <a href="mailto:swaldon@cs.unc.edu" target="_blank">swaldon@cs.unc.edu</a><br>
>><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at:<br>
> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
><br>
<br>
<br>
<br>
--<br>
</div></div><div><div>Unpaid intern in BillsBasement at noware dot com<br>
</div></div></blockquote></div><br></div>
</blockquote></div>
</div></div></blockquote></div><br></div>