vtkGDCMPolyDataWriter RTStruct from scratch, segmentation fault

Hi all,

I’m trying to figure out how to use vtkGDCMPolyDataWriter. I’m currently able to write user-created contours and have them display correctly in a DICOM reader, but only using the “cheating” strategy in this example: http://gdcm.sourceforge.net/html/GenerateRTSTRUCT_8cxx-example.html (the “cheating” strategy is setting MedicalImageProperties and RTStructSetProperties from a vtkGDCMPolyDataReader).

When I try to include the following lines in the example that append a blank PolyData, however, I get a segmentation fault on writer -> Write(). I’ve also been trying to go through the RTStructSetProperties source code and setting all the variables I can manually, but again this leads to a segmentation fault . Does anybody know of a guide or have any advice that could help me learn how to do this?

Thank you,
Harry

Update: I’ve now got the example code working with my user-made structures, although to be honest I’m not sure what I changed. All that is clear to me is that InitializeRTStructSet is the step that allows new structure properties to be set.
That being said, can somebody please explain to me the following block from the example:

vtkRTStructSetProperties* theProperties = vtkRTStructSetProperties::New();
writer->SetRTStructSetProperties(theProperties);
writer->InitializeRTStructSet(theDirName,
      reader->GetRTStructSetProperties()->GetStructureSetLabel(),
      reader->GetRTStructSetProperties()->GetStructureSetName(),
      roiNames, roiAlgorithms, roiTypes);
writer->SetRTStructSetProperties(theProperties);
writer->Write();

Specifically, why are we setting the properties twice? It seems like InitializeRTStructSet must modify theProperties between the two calls, but browsing through the source code (https://github.com/malaterre/GDCM/blob/master/Utilities/VTK/vtkGDCMPolyDataWriter.cxx) , this doesn’t seem to happen. Either way, this doesn’t matter apart from satisfying my curiosity, and this thread can probably be deleted.