<div dir="ltr">I'm having a couple of problems with clipping polygon data, which the following code exposes:<div> - Clipping a closed polygon, which should all be retained, it loses the closing vertex</div><div> - Clipping all the data so there is nothing left, various things then crash because the clipper produces an array with one entry consisting of a single null pointer</div>
<div><br></div><div>To reproduce these, in the first case define USE_CLIPPER but not CLIP_TO_NOTHING in the following code, and in the second case define them both.</div><div><br></div><div>This seems such ancient code; am I doing something wrong?  I'm using 6.1.</div>
<div><br clear="all"><div>Many thanks,</div><div><br></div><div>Richard</div><div><br></div><div><br></div><div><br></div><div><div>#define USE_CLIPPER 1</div><div>#define CLIP_TO_NOTHING 1</div><div><br></div><div><span class="" style="white-space:pre">    </span>// create circle of points, joined by lines into a closed loop, on the x,y plane</div>
<div><span class="" style="white-space:pre">    </span>vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New();</div><div><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();</div>
<div><span class="" style="white-space:pre">    </span>vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();</div><div><span class="" style="white-space:pre">    </span>vtkIdType* lineIndices = new vtkIdType[21];</div>
<div><span class="" style="white-space:pre">    </span>for (int i = 0; i< 20; i++)</div><div><span class="" style="white-space:pre">     </span>{</div><div><span class="" style="white-space:pre">          </span>const double angle = 2.0*vtkMath::Pi()*i/20.0;</div>
<div><span class="" style="white-space:pre">            </span>points->InsertPoint(static_cast<vtkIdType>(i), 100*cos(angle), 100*sin(angle), 0.0 );</div><div><span class="" style="white-space:pre">             </span>lineIndices[i] = static_cast<vtkIdType>(i);</div>
<div><span class="" style="white-space:pre">    </span>}</div><div><span class="" style="white-space:pre">  </span>lineIndices[20] = 0;</div><div><span class="" style="white-space:pre">       </span>lines->InsertNextCell(21,lineIndices);</div>
<div><span class="" style="white-space:pre">    </span>delete [] lineIndices;</div><div><span class="" style="white-space:pre">     </span>pd->SetPoints(points);</div><div><span class="" style="white-space:pre">  </span>pd->SetLines(lines);</div>
<div><span class="" style="white-space:pre">    </span></div><div><span class="" style="white-space:pre">   </span>// clipping</div><div>#if USE_CLIPPER</div><div><span class="" style="white-space:pre">  </span>vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();</div>
<div>#if CLIP_TO_NOTHING</div><div><span class="" style="white-space:pre">  </span>plane->SetOrigin(0, 0, -1.0); // no data on this plane</div><div>#else</div><div><span class="" style="white-space:pre">      </span>plane->SetOrigin(0, 0, 0.0); // all the data is on this plane</div>
<div>#endif</div><div><span class="" style="white-space:pre">       </span>plane->SetNormal(0, 0, 1);</div><div><span class="" style="white-space:pre">      </span>vtkSmartPointer<vtkClipPolyData> clipper = vtkSmartPointer<vtkClipPolyData>::New(); </div>
<div><span class="" style="white-space:pre">    </span>clipper->SetInputData(pd);</div><div><span class="" style="white-space:pre">      </span>clipper->SetClipFunction(plane);</div><div><span class="" style="white-space:pre">        </span>clipper->GenerateClipScalarsOn();</div>
<div><span class="" style="white-space:pre">    </span>clipper->InsideOutOn();</div><div><span class="" style="white-space:pre"> </span>clipper->Update();</div><div>#endif</div><div><br></div><div><span class="" style="white-space:pre">        </span>// windows and interactors</div>
<div><span class="" style="white-space:pre">    </span>vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();</div><div><span class="" style="white-space:pre">   </span>vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();</div>
<div><span class="" style="white-space:pre">    </span>renderWindow->AddRenderer(renderer);</div><div><span class="" style="white-space:pre">    </span>vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();</div>
<div><span class="" style="white-space:pre">    </span>renderWindowInteractor->SetRenderWindow(renderWindow);</div><div><span class="" style="white-space:pre">  </span>renderWindow->SetSize(600, 600);</div><div><br></div>
<div><span class="" style="white-space:pre">    </span>// widget</div><div><span class="" style="white-space:pre">  </span>vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep = vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();</div>
<div><span class="" style="white-space:pre">    </span>contourRep->GetLinesProperty()->SetColor(1, 0, 0); //set color to red</div><div><span class="" style="white-space:pre">        </span>vtkSmartPointer<vtkContourWidget> contourWidget = vtkSmartPointer<vtkContourWidget>::New();</div>
<div><span class="" style="white-space:pre">    </span>contourWidget->SetInteractor(renderWindowInteractor);</div><div><span class="" style="white-space:pre">   </span>contourWidget->SetRepresentation(contourRep);</div><div>
<span class="" style="white-space:pre">       </span>contourWidget->On();<span class="" style="white-space:pre">   </span></div><div><br></div><div>#if USE_CLIPPER</div><div><span class="" style="white-space:pre">    </span>contourWidget->Initialize(clipper->GetOutput());</div>
<div>#else</div><div><span class="" style="white-space:pre">        </span>contourWidget->Initialize(pd);</div><div>#endif</div><div><span class="" style="white-space:pre">     </span></div><div><span class="" style="white-space:pre">   </span>// run</div>
<div><span class="" style="white-space:pre">    </span>contourWidget->Render();</div><div><span class="" style="white-space:pre">        </span>renderer->ResetCamera();</div><div><span class="" style="white-space:pre">        </span>renderWindow->Render();</div>
<div><span class="" style="white-space:pre">    </span>renderWindowInteractor->Initialize();</div><div><span class="" style="white-space:pre">   </span>renderWindowInteractor->Start();</div><div><span class="" style="white-space:pre">        </span>contourWidget->Off();<span class="" style="white-space:pre">  </span></div>
</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>-- <br><div dir="ltr"><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif">Richard Whitehead </span><b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">–</span></b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif"> Senior Imaging Engineer</span></p>
<p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">Michelson Diagnostics Ltd</span></b></p><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt">
<b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">M:</span></b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif"> +44 (0)7905 955276   </span><b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">T:</span></b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif"> +44 (0)20 8308 1695</span></p>
<p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">E: </span></b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(0,176,240)"><a href="mailto:richard.whitehead@vivosight.com" style="color:rgb(17,85,204)" target="_blank"><span style="color:rgb(0,176,240)">richard.whitehead@vivosight.com</span></a></span><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif">   </span><b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">W:</span></b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif"> </span><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(0,176,240)"><a href="http://www.vivosight.com/" style="color:rgb(17,85,204)" target="_blank"><span style="color:rgb(0,176,240)">www.vivosight.com</span></a></span></p>
<p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><br></p><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><a href="http://www.vivosight.com/" target="_blank"><span style="color:windowtext;text-decoration:none"><img src="https://sites.google.com/a/vivosight.com/logo/_/rsrc/1361922206747/home/VivoSight.png" border="0"></span></a></p>
<p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><br></p><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"></p><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt">
<span style="font-size:7.5pt;font-family:Arial,sans-serif;color:gray">Michelson Diagnostics Ltd, 1 Grays Farm Production Village, Grays Farm Road, Orpington, Kent  BR5 3BD, UK</span></p><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt">
<span style="font-size:7.5pt;font-family:Arial,sans-serif;color:gray">Registered Office: 3 Shearwater, Maidstone, ME16 0DW.     Registered in England No. 5732681</span></p></div>
</div></div>