<html><head><style>body{font-family:Merriweather,Arial;font-size:13px}</style></head><body style="word-wrap:break-word;line-break:after-white-space"><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">Hello everybody, I’m trying to gain a bit more awareness on C++ programming and I wanted to try to iterate using C++11/14 iterators over a vtkPolyData structure but I’m experiencing SIGSEV. </div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">I will present before the code structure.</div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">1) I have a `<a href="https://gitlab.com/snippets/1733515">PolyDataWrapper</a>` class that accepts as argument a pointer to a `vtkPolyData` structure containing a triangulated surface. This class offers a method `iterateOver<Item>` that returns an iterator so that you can iterate over the points of the vtkPolydata doing</div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">    </div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">    for (PolyDataPoint p : polydata.iterateOver<PolyDataPoint>()){</div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">        // Do something</div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">     }</div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">And equivalently for cells:</div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">    for (PolyDataCell c : postdata.iterateOver<PolyDataCell>() { /*…*/}</div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">And moreover it exposes some methods like `GetCellPoints` that use the underlying pointer to the “raw” vtkPolyData object.</div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">Here's the class for the <a href="https://gitlab.com/snippets/1733518">PolyDataCell</a></div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">2) I have a `<a href="https://gitlab.com/snippets/1733520">PolyDataIterator</a>` that implements the C++14 compatible range-based for loop. </div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">The problem is that running the following code raises a Segmentation fault if I’m using the PolyDataCell::GetCellPoints() method that the only thing it does it calling the PolyDataWrapper::GetCellPoints(PolyDataCell *).</div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto">I probably did a mistake passing around pointers, but I was thinking that maybe I’m doing something that is messed up by the garbage collection of the vtk smart pointer. Could it be? Help is very much appreciated!</div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;color:rgba(51,51,51,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Merriweather,Arial;font-size:13px;margin:0px"><div id="bloop_customfont" style="margin:0px">#define SPHERE_RADIUS 1.0</div><div id="bloop_customfont" style="margin:0px"><br></div><div id="bloop_customfont" style="margin:0px">#include "vtkNew.h"</div><div id="bloop_customfont" style="margin:0px">#include "vtkSmartPointer.h"</div><div id="bloop_customfont" style="margin:0px">#include "vtkTriangleFilter.h"</div><div id="bloop_customfont" style="margin:0px">#include "vtkSphereSource.h"</div><div id="bloop_customfont" style="margin:0px"><br></div><div id="bloop_customfont" style="margin:0px">#include "types.h"</div><div id="bloop_customfont" style="margin:0px">#include "PolyDataWrapper.h"</div><div id="bloop_customfont" style="margin:0px"><br></div><div id="bloop_customfont" style="margin:0px">vtkNew<vtkSphereSource> sphere;</div><div id="bloop_customfont" style="margin:0px">sphere->SetRadius(SPHERE_RADIUS);</div><div id="bloop_customfont" style="margin:0px">sphere->Update();</div><div id="bloop_customfont" style="margin:0px"><br></div><div id="bloop_customfont" style="margin:0px">// Transform the sphere into a PolyData</div><div id="bloop_customfont" style="margin:0px">vtkNew<vtkTriangleFilter> triFilter;</div><div id="bloop_customfont" style="margin:0px">triFilter->SetInputData(sphere->GetOutput());</div><div id="bloop_customfont" style="margin:0px">triFilter->Update();</div><div id="bloop_customfont" style="margin:0px"><br></div><div id="bloop_customfont" style="margin:0px">// Triangulated version of the sphere</div><div id="bloop_customfont" style="margin:0px">vtkSmartPointer<vtkPolyData> triSphere = triFilter->GetOutput();</div><div id="bloop_customfont" style="margin:0px"><br></div><div id="bloop_customfont" style="margin:0px">// Build cells</div><div id="bloop_customfont" style="margin:0px">triSphere->BuildCells();</div><div id="bloop_customfont" style="margin:0px"><br></div><div id="bloop_customfont" style="margin:0px">// Get total number of points</div><div id="bloop_customfont" style="margin:0px">IdType nPoints = triSphere->GetNumberOfPoints();</div><div id="bloop_customfont" style="margin:0px"><br></div><div id="bloop_customfont" style="margin:0px">// Get total number of cells</div><div id="bloop_customfont" style="margin:0px">IdType nCells = triSphere->GetNumberOfCells();</div><div id="bloop_customfont" style="margin:0px"><br></div><div id="bloop_customfont" style="margin:0px">//Initialize PolyDataWrapper</div><div id="bloop_customfont" style="margin:0px">PolyDataWrapper polydata(triFilter->GetOutput());</div><div id="bloop_customfont" style="margin:0px"><br></div><div id="bloop_customfont" style="margin:0px">for(PolyDataCell cell : polydata.iterateOver<PolyDataCell>()) {</div><div id="bloop_customfont" style="margin:0px">std::array<PolyDataPoint, 3> points;</div><div id="bloop_customfont" style="margin:0px">    points = polydata.GetCellPoints(cell); // This is ok</div><div id="bloop_customfont" style="margin:0px">    // points = cell.GetCellPoints(); // This causes SIGSEV</div><div id="bloop_customfont" style="margin:0px">}</div><div><br></div></div><div id="bloop_sign_1531723770501730048" class="bloop_sign">
         
        <title></title>
     
     
        <pre>          _   
-.     .´  |∞∞∞∞
  ',  ;    |∞∞∞∞∞∞
    ˜˜     |∞∞∞∞∞∞∞∞∞ RdB
    ,.,    |∞∞∞∞∞∞
  .'   '.  |∞∞∞∞
-'       `’

<a href="http://rdb.is">http://rdb.is</a>
</pre>
     
</div></body></html>