Discussion:
[vtkusers] Segmentation fault
elena bresciani
2014-04-07 15:00:08 UTC
Permalink
Hello everybody!

I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how to modify
the code to make it run.

Here's the portion of the code that I'm talking about:


*vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();*
(the reader is a vtkXMLPolyDataReader)



*vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ; for(vtkIdType i = 0; i <
PointNormalArray->GetNumberOfTuples(); i++) {....}*

everytime I call GetNumberOfTuples I have this error so I think the problem
is on PointNormalArray.

Can somebody help me?

Thanks in advance

Elena
Bill Lorensen
2014-04-07 15:18:23 UTC
Permalink
Have you applied
reader->Update();

before you request the reader's output?


On Mon, Apr 7, 2014 at 11:00 AM, elena bresciani
Post by elena bresciani
Hello everybody!
I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how to modify
the code to make it run.
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
(the reader is a vtkXMLPolyDataReader)
vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ;
for(vtkIdType i = 0; i < PointNormalArray->GetNumberOfTuples(); i++) {....}
everytime I call GetNumberOfTuples I have this error so I think the problem
is on PointNormalArray.
Can somebody help me?
Thanks in advance
Elena
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Unpaid intern in BillsBasement at noware dot com
elena bresciani
2014-04-07 15:32:03 UTC
Permalink
yes
Post by Bill Lorensen
Have you applied
reader->Update();
before you request the reader's output?
On Mon, Apr 7, 2014 at 11:00 AM, elena bresciani
Post by elena bresciani
Hello everybody!
I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how to
modify
Post by elena bresciani
the code to make it run.
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
(the reader is a vtkXMLPolyDataReader)
vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ;
for(vtkIdType i = 0; i < PointNormalArray->GetNumberOfTuples(); i++)
{....}
Post by elena bresciani
everytime I call GetNumberOfTuples I have this error so I think the
problem
Post by elena bresciani
is on PointNormalArray.
Can somebody help me?
Thanks in advance
Elena
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Unpaid intern in BillsBasement at noware dot com
Bill Lorensen
2014-04-07 17:00:06 UTC
Permalink
Perhaps the reader is returning normals as doubles?

On Mon, Apr 7, 2014 at 11:32 AM, elena bresciani
yes
Post by Bill Lorensen
Have you applied
reader->Update();
before you request the reader's output?
On Mon, Apr 7, 2014 at 11:00 AM, elena bresciani
Post by elena bresciani
Hello everybody!
I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how to modify
the code to make it run.
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
(the reader is a vtkXMLPolyDataReader)
vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ;
for(vtkIdType i = 0; i < PointNormalArray->GetNumberOfTuples(); i++) {....}
everytime I call GetNumberOfTuples I have this error so I think the problem
is on PointNormalArray.
Can somebody help me?
Thanks in advance
Elena
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Unpaid intern in BillsBasement at noware dot com
--
Unpaid intern in BillsBasement at noware dot com
Goodwin Lawlor
2014-04-07 17:11:21 UTC
Permalink
Hi Elena,

I coud be wrong but I dont think this is correct:

vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();


reader->GetOutput() returns a regular pointer to a vtkPolydata not a smart
pointer.

Try:

vtkPolyData *polydata = reader->GetOutput();

instead.

hth

Goodwin
Post by elena bresciani
Hello everybody!
I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how to
modify the code to make it run.
*vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();*
(the reader is a vtkXMLPolyDataReader)
*vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ; for(vtkIdType i = 0; i <
PointNormalArray->GetNumberOfTuples(); i++) {....}*
everytime I call GetNumberOfTuples I have this error so I think the
problem is on PointNormalArray.
Can somebody help me?
Thanks in advance
Elena
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
Shawn Waldon
2014-04-07 17:17:26 UTC
Permalink
Hi Goodwin,

It shouldn't be causing the segfault. That line will create a new smart
pointer and set its internal pointer to the reader's output, incrementing
the reference count.
See
http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers#Getting_an_Object_with_a_Smart_Pointerfor
details. If the reference increment is unnecessary, then it is still
only a small performance gain and not a segfault causing bug.

My guess for the segfault is what Bill said: the normals are in a
vtkDoubleArray not a vtkFloatArray so SafeDownCast is returning NULL.

HTH,

Shawn


On Mon, Apr 7, 2014 at 1:11 PM, Goodwin Lawlor <
Post by Goodwin Lawlor
Hi Elena,
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
reader->GetOutput() returns a regular pointer to a vtkPolydata not a smart
pointer.
vtkPolyData *polydata = reader->GetOutput();
instead.
hth
Goodwin
On Mon, Apr 7, 2014 at 4:00 PM, elena bresciani <
Post by elena bresciani
Hello everybody!
I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how to
modify the code to make it run.
*vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();*
(the reader is a vtkXMLPolyDataReader)
*vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ; for(vtkIdType i = 0; i <
PointNormalArray->GetNumberOfTuples(); i++) {....}*
everytime I call GetNumberOfTuples I have this error so I think the
problem is on PointNormalArray.
Can somebody help me?
Thanks in advance
Elena
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Shawn Waldon
Graduate Research Assistant
Department of Computer Science
University of North Carolina at Chapel Hill
***@cs.unc.edu
Goodwin Lawlor
2014-04-07 17:31:26 UTC
Permalink
Thanks for that link Shawn and setting me straight (I did day I could be
wrong ;-))

My logic was that if you had to do:

vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();

then initializing a smart pointer not created with the form on the RHS
above wouldn't work...

Goodwin
Post by Shawn Waldon
Hi Goodwin,
It shouldn't be causing the segfault. That line will create a new smart
pointer and set its internal pointer to the reader's output, incrementing
the reference count.
See
http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers#Getting_an_Object_with_a_Smart_Pointerfor details. If the reference increment is unnecessary, then it is still
only a small performance gain and not a segfault causing bug.
My guess for the segfault is what Bill said: the normals are in a
vtkDoubleArray not a vtkFloatArray so SafeDownCast is returning NULL.
HTH,
Shawn
On Mon, Apr 7, 2014 at 1:11 PM, Goodwin Lawlor <
Post by Goodwin Lawlor
Hi Elena,
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
reader->GetOutput() returns a regular pointer to a vtkPolydata not a
smart pointer.
vtkPolyData *polydata = reader->GetOutput();
instead.
hth
Goodwin
On Mon, Apr 7, 2014 at 4:00 PM, elena bresciani <
Post by elena bresciani
Hello everybody!
I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how to
modify the code to make it run.
*vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();*
(the reader is a vtkXMLPolyDataReader)
*vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ; for(vtkIdType i = 0; i <
PointNormalArray->GetNumberOfTuples(); i++) {....}*
everytime I call GetNumberOfTuples I have this error so I think the
problem is on PointNormalArray.
Can somebody help me?
Thanks in advance
Elena
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Shawn Waldon
Graduate Research Assistant
Department of Computer Science
University of North Carolina at Chapel Hill
elena bresciani
2014-04-08 07:19:31 UTC
Permalink
Thank you guys,

I tried changing the type of PointNormalArray in vtkDoubleArray

*vtkDoubleArray *PointNormalArray = vtkDoubleArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ; *

but I still have the segfault.

Elena
Post by Goodwin Lawlor
Thanks for that link Shawn and setting me straight (I did day I could be
wrong ;-))
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
then initializing a smart pointer not created with the form on the RHS
above wouldn't work...
Goodwin
Post by Shawn Waldon
Hi Goodwin,
It shouldn't be causing the segfault. That line will create a new smart
pointer and set its internal pointer to the reader's output, incrementing
the reference count.
See
http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers#Getting_an_Object_with_a_Smart_Pointerfor details. If the reference increment is unnecessary, then it is still
only a small performance gain and not a segfault causing bug.
My guess for the segfault is what Bill said: the normals are in a
vtkDoubleArray not a vtkFloatArray so SafeDownCast is returning NULL.
HTH,
Shawn
On Mon, Apr 7, 2014 at 1:11 PM, Goodwin Lawlor <
Post by Goodwin Lawlor
Hi Elena,
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
reader->GetOutput() returns a regular pointer to a vtkPolydata not a
smart pointer.
vtkPolyData *polydata = reader->GetOutput();
instead.
hth
Goodwin
On Mon, Apr 7, 2014 at 4:00 PM, elena bresciani <
Post by elena bresciani
Hello everybody!
I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how to
modify the code to make it run.
*vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();*
(the reader is a vtkXMLPolyDataReader)
*vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ; for(vtkIdType i = 0; i <
PointNormalArray->GetNumberOfTuples(); i++) {....}*
everytime I call GetNumberOfTuples I have this error so I think the
problem is on PointNormalArray.
Can somebody help me?
Thanks in advance
Elena
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Shawn Waldon
Graduate Research Assistant
Department of Computer Science
University of North Carolina at Chapel Hill
Bill Lorensen
2014-04-08 11:58:32 UTC
Permalink
Please post a small, complete, compilable example that illustrates your problem.

On Tue, Apr 8, 2014 at 3:19 AM, elena bresciani
Post by elena bresciani
Thank you guys,
I tried changing the type of PointNormalArray in vtkDoubleArray
vtkDoubleArray *PointNormalArray = vtkDoubleArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ;
but I still have the segfault.
Elena
Post by Goodwin Lawlor
Thanks for that link Shawn and setting me straight (I did day I could be
wrong ;-))
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
then initializing a smart pointer not created with the form on the RHS
above wouldn't work...
Goodwin
Post by Shawn Waldon
Hi Goodwin,
It shouldn't be causing the segfault. That line will create a new smart
pointer and set its internal pointer to the reader's output, incrementing
the reference count.
See
http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers#Getting_an_Object_with_a_Smart_Pointer
for details. If the reference increment is unnecessary, then it is still
only a small performance gain and not a segfault causing bug.
My guess for the segfault is what Bill said: the normals are in a
vtkDoubleArray not a vtkFloatArray so SafeDownCast is returning NULL.
HTH,
Shawn
On Mon, Apr 7, 2014 at 1:11 PM, Goodwin Lawlor
Post by Goodwin Lawlor
Hi Elena,
Post by elena bresciani
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
reader->GetOutput() returns a regular pointer to a vtkPolydata not a
smart pointer.
vtkPolyData *polydata = reader->GetOutput();
instead.
hth
Goodwin
On Mon, Apr 7, 2014 at 4:00 PM, elena bresciani
Post by elena bresciani
Hello everybody!
I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how to
modify the code to make it run.
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
(the reader is a vtkXMLPolyDataReader)
vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ;
for(vtkIdType i = 0; i < PointNormalArray->GetNumberOfTuples(); i++)
{....}
everytime I call GetNumberOfTuples I have this error so I think the
problem is on PointNormalArray.
Can somebody help me?
Thanks in advance
Elena
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Shawn Waldon
Graduate Research Assistant
Department of Computer Science
University of North Carolina at Chapel Hill
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Unpaid intern in BillsBasement at noware dot com
elena bresciani
2014-04-08 12:33:55 UTC
Permalink
Here it is, I omitted the inclusion of the header files and the output
section



int main ( int argc, char *argv[] )
{

std::string filename = argv[1];

// Read data from the file
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(filename.c_str());
reader->Update();

// polydata object
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();

// get normals
vtkDoubleArray *pointNormalsArray = vtkDoubleArray::SafeDownCast
(polydata->GetPointData()->GetNormals());


vtkSmartPointer<vtkPolyData> newpolydata =
vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkPoints> newPoints =
vtkSmartPointer<vtkPoints>::New();

// for every point p1 in the polydata find the point p2 which lies on
the normal at a distance D from p1

for(vtkIdType i = 0; i < pointNormalsArray->GetNumberOfTuples(); i++)

{
double p1[3];
polydata->GetPoint(i,p1); //prendo il punto

double pN[3];
pointNormalsArray->GetTuple(i, pN);

double p2[3];
double D=2*atoi(argv[3]);
p2[0]=p1[0]-pN[0]*D;
p2[1]=p1[1]-pN[1]*D;
p2[2]=p1[2]-pN[2]*D;


vtkIdType pid[1];
pid[0]=newPoints->InsertNextPoint(p2);

}

//set points to polydata
newpolydata->SetPoints(newPoints);

return EXIT_SUCCESS;
}
Post by Bill Lorensen
Please post a small, complete, compilable example that illustrates your problem.
On Tue, Apr 8, 2014 at 3:19 AM, elena bresciani
Post by elena bresciani
Thank you guys,
I tried changing the type of PointNormalArray in vtkDoubleArray
vtkDoubleArray *PointNormalArray = vtkDoubleArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ;
but I still have the segfault.
Elena
2014-04-07 19:31 GMT+02:00 Goodwin Lawlor <
Post by Goodwin Lawlor
Thanks for that link Shawn and setting me straight (I did day I could be
wrong ;-))
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
then initializing a smart pointer not created with the form on the RHS
above wouldn't work...
Goodwin
Post by Shawn Waldon
Hi Goodwin,
It shouldn't be causing the segfault. That line will create a new
smart
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
pointer and set its internal pointer to the reader's output,
incrementing
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
the reference count.
See
http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers#Getting_an_Object_with_a_Smart_Pointer
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
for details. If the reference increment is unnecessary, then it is
still
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
only a small performance gain and not a segfault causing bug.
My guess for the segfault is what Bill said: the normals are in a
vtkDoubleArray not a vtkFloatArray so SafeDownCast is returning NULL.
HTH,
Shawn
On Mon, Apr 7, 2014 at 1:11 PM, Goodwin Lawlor
Post by Goodwin Lawlor
Hi Elena,
Post by elena bresciani
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
reader->GetOutput() returns a regular pointer to a vtkPolydata not a
smart pointer.
vtkPolyData *polydata = reader->GetOutput();
instead.
hth
Goodwin
On Mon, Apr 7, 2014 at 4:00 PM, elena bresciani
Post by elena bresciani
Hello everybody!
I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how to
modify the code to make it run.
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
(the reader is a vtkXMLPolyDataReader)
vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ;
for(vtkIdType i = 0; i < PointNormalArray->GetNumberOfTuples(); i++)
{....}
everytime I call GetNumberOfTuples I have this error so I think the
problem is on PointNormalArray.
Can somebody help me?
Thanks in advance
Elena
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Shawn Waldon
Graduate Research Assistant
Department of Computer Science
University of North Carolina at Chapel Hill
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Unpaid intern in BillsBasement at noware dot com
Bill Lorensen
2014-04-08 13:12:28 UTC
Permalink
Are you certain that the input file has Normals?
Post by elena bresciani
Here it is, I omitted the inclusion of the header files and the output
section
int main ( int argc, char *argv[] )
{
std::string filename = argv[1];
// Read data from the file
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(filename.c_str());
reader->Update();
// polydata object
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
// get normals
vtkDoubleArray *pointNormalsArray = vtkDoubleArray::SafeDownCast
(polydata->GetPointData()->GetNormals());
vtkSmartPointer<vtkPolyData> newpolydata =
vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkPoints> newPoints =
vtkSmartPointer<vtkPoints>::New();
// for every point p1 in the polydata find the point p2 which lies on
the normal at a distance D from p1
for(vtkIdType i = 0; i < pointNormalsArray->GetNumberOfTuples(); i++)
{
double p1[3];
polydata->GetPoint(i,p1); //prendo il punto
double pN[3];
pointNormalsArray->GetTuple(i, pN);
double p2[3];
double D=2*atoi(argv[3]);
p2[0]=p1[0]-pN[0]*D;
p2[1]=p1[1]-pN[1]*D;
p2[2]=p1[2]-pN[2]*D;
vtkIdType pid[1];
pid[0]=newPoints->InsertNextPoint(p2);
}
//set points to polydata
newpolydata->SetPoints(newPoints);
return EXIT_SUCCESS;
}
Post by Bill Lorensen
Please post a small, complete, compilable example that illustrates your problem.
On Tue, Apr 8, 2014 at 3:19 AM, elena bresciani
Post by elena bresciani
Thank you guys,
I tried changing the type of PointNormalArray in vtkDoubleArray
vtkDoubleArray *PointNormalArray = vtkDoubleArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ;
but I still have the segfault.
Elena
2014-04-07 19:31 GMT+02:00 Goodwin Lawlor <
Post by Goodwin Lawlor
Thanks for that link Shawn and setting me straight (I did day I could
be
Post by elena bresciani
Post by Goodwin Lawlor
wrong ;-))
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
then initializing a smart pointer not created with the form on the RHS
above wouldn't work...
Goodwin
Post by Shawn Waldon
Hi Goodwin,
It shouldn't be causing the segfault. That line will create a new
smart
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
pointer and set its internal pointer to the reader's output,
incrementing
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
the reference count.
See
http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers#Getting_an_Object_with_a_Smart_Pointer
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
for details. If the reference increment is unnecessary, then it is
still
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
only a small performance gain and not a segfault causing bug.
My guess for the segfault is what Bill said: the normals are in a
vtkDoubleArray not a vtkFloatArray so SafeDownCast is returning NULL.
HTH,
Shawn
On Mon, Apr 7, 2014 at 1:11 PM, Goodwin Lawlor
Post by Goodwin Lawlor
Hi Elena,
Post by elena bresciani
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
reader->GetOutput() returns a regular pointer to a vtkPolydata not a
smart pointer.
vtkPolyData *polydata = reader->GetOutput();
instead.
hth
Goodwin
On Mon, Apr 7, 2014 at 4:00 PM, elena bresciani
Post by elena bresciani
Hello everybody!
I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how to
modify the code to make it run.
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
(the reader is a vtkXMLPolyDataReader)
vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ;
for(vtkIdType i = 0; i < PointNormalArray->GetNumberOfTuples(); i++)
{....}
everytime I call GetNumberOfTuples I have this error so I think the
problem is on PointNormalArray.
Can somebody help me?
Thanks in advance
Elena
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Shawn Waldon
Graduate Research Assistant
Department of Computer Science
University of North Carolina at Chapel Hill
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Unpaid intern in BillsBasement at noware dot com
Goodwin Lawlor
2014-04-08 13:29:06 UTC
Permalink
Hi Elena,

You code worked fine when

- vtkFloatArray is used to down cast (on win32)
- the input has normals. (as Bill asked)

I reproduced your bug when the input dataset didn't have normals... insert
a vtkPolyDataNormals filter into your code to check this out.

Goodwin
Post by Bill Lorensen
Are you certain that the input file has Normals?
Post by elena bresciani
Here it is, I omitted the inclusion of the header files and the output
section
int main ( int argc, char *argv[] )
{
std::string filename = argv[1];
// Read data from the file
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(filename.c_str());
reader->Update();
// polydata object
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
// get normals
vtkDoubleArray *pointNormalsArray = vtkDoubleArray::SafeDownCast
(polydata->GetPointData()->GetNormals());
vtkSmartPointer<vtkPolyData> newpolydata =
vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkPoints> newPoints =
vtkSmartPointer<vtkPoints>::New();
// for every point p1 in the polydata find the point p2 which lies on
the normal at a distance D from p1
for(vtkIdType i = 0; i < pointNormalsArray->GetNumberOfTuples(); i++)
{
double p1[3];
polydata->GetPoint(i,p1); //prendo il punto
double pN[3];
pointNormalsArray->GetTuple(i, pN);
double p2[3];
double D=2*atoi(argv[3]);
p2[0]=p1[0]-pN[0]*D;
p2[1]=p1[1]-pN[1]*D;
p2[2]=p1[2]-pN[2]*D;
vtkIdType pid[1];
pid[0]=newPoints->InsertNextPoint(p2);
}
//set points to polydata
newpolydata->SetPoints(newPoints);
return EXIT_SUCCESS;
}
Post by Bill Lorensen
Please post a small, complete, compilable example that illustrates your problem.
On Tue, Apr 8, 2014 at 3:19 AM, elena bresciani
Post by elena bresciani
Thank you guys,
I tried changing the type of PointNormalArray in vtkDoubleArray
vtkDoubleArray *PointNormalArray = vtkDoubleArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ;
but I still have the segfault.
Elena
2014-04-07 19:31 GMT+02:00 Goodwin Lawlor <
Post by Goodwin Lawlor
Thanks for that link Shawn and setting me straight (I did day I could
be
Post by elena bresciani
Post by Goodwin Lawlor
wrong ;-))
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
then initializing a smart pointer not created with the form on the RHS
above wouldn't work...
Goodwin
Post by Shawn Waldon
Hi Goodwin,
It shouldn't be causing the segfault. That line will create a new
smart
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
pointer and set its internal pointer to the reader's output,
incrementing
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
the reference count.
See
http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers#Getting_an_Object_with_a_Smart_Pointer
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
for details. If the reference increment is unnecessary, then it is
still
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
only a small performance gain and not a segfault causing bug.
My guess for the segfault is what Bill said: the normals are in a
vtkDoubleArray not a vtkFloatArray so SafeDownCast is returning NULL.
HTH,
Shawn
On Mon, Apr 7, 2014 at 1:11 PM, Goodwin Lawlor
Post by Goodwin Lawlor
Hi Elena,
Post by elena bresciani
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
reader->GetOutput() returns a regular pointer to a vtkPolydata not a
smart pointer.
vtkPolyData *polydata = reader->GetOutput();
instead.
hth
Goodwin
On Mon, Apr 7, 2014 at 4:00 PM, elena bresciani
Post by elena bresciani
Hello everybody!
I need your help with a segmentation fault error.
Using gdb I understood where it is generated but I don't know how
to
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
Post by Goodwin Lawlor
Post by elena bresciani
modify the code to make it run.
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
(the reader is a vtkXMLPolyDataReader)
vtkFloatArray *PointNormalArray = vtkFloatArray::SafeDownCast(
polydata->GetPointData()->GetNormals() ) ;
for(vtkIdType i = 0; i < PointNormalArray->GetNumberOfTuples();
i++)
Post by elena bresciani
Post by Goodwin Lawlor
Post by Shawn Waldon
Post by Goodwin Lawlor
Post by elena bresciani
{....}
everytime I call GetNumberOfTuples I have this error so I think the
problem is on PointNormalArray.
Can somebody help me?
Thanks in advance
Elena
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Shawn Waldon
Graduate Research Assistant
Department of Computer Science
University of North Carolina at Chapel Hill
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
--
Unpaid intern in BillsBasement at noware dot com
elena bresciani
2014-04-09 09:26:48 UTC
Permalink
yeah, now it works. I was focusing on pointers and memory management issues
and I really didn't notice what something was missing.

Thank you VERY much guys!

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