Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add Set/Get and XML macros for iterable STL container properties #973

Closed

Conversation

Sunderlandkyl
Copy link
Member

@Sunderlandkyl Sunderlandkyl commented Jun 18, 2018

Adds macros to Read/Write/Print/Copy iterable properties.

Example usage:

  • Numeric container:
    vtkMRMLWriteXMLStdVectorMacro(property, Property, std::deque<int>);

  • String container:
    vtkMRMLWriteXMLStdStringVectorMacro(property, Property, std::vector);

See also this related merge request in VTK: https://gitlab.kitware.com/vtk/vtk/merge_requests/4427
It's not required for this change, but it adds some convenience macros for setting/getting STL containers.

Also added generic Set/Get macros that work with STL containers.
Currently, STL containers cannot use the generic vtkSetMacro/vtkGetMacro types since those macros require a "<<" operator within vtkDebugMacro

openigtlink/SlicerOpenIGTLink#36

cc: @lassoan

@Sunderlandkyl Sunderlandkyl force-pushed the std_vector_xml_macros branch 2 times, most recently from 4bb7cf9 to c05b36f Compare June 22, 2018 18:20
@Sunderlandkyl Sunderlandkyl changed the title ENH: Add XML macros for iterable STL container MRML node properties ENH: Add Set/Get and XML macros for iterable STL container properties Jun 22, 2018
@Sunderlandkyl Sunderlandkyl force-pushed the std_vector_xml_macros branch 2 times, most recently from 3491446 to 0f022db Compare June 22, 2018 21:29
@lassoan
Copy link
Contributor

lassoan commented Jun 22, 2018

Thanks a lot Kyle, it looks good! I would just ask for one change.

We may need different implementation in the future for managing float/double and integer vectors. Therefore, it would be more future-proof if we created separate macros for float and integer (e.g., set large number of decimal digits for floats for loss-less writing to file; handle special values, such as nan, inf, ...). vtkMRMLWriteXMLStdFloatVectorMacro and vtkMRMLWriteXMLStdIntVectorMacro name should work (and of course not just the writer macros but others would need to be renamed as well). If you don't need integer vector macros then for you can just rename vtkMRML...StdVectorMacro to vtkMRML...StdFloatVectorMacro.

@Sunderlandkyl
Copy link
Member Author

Sunderlandkyl commented Jun 23, 2018

Makes sense. I'll add the int macros as well. I believe that there are some integer parameters.

@Sunderlandkyl Sunderlandkyl force-pushed the std_vector_xml_macros branch 2 times, most recently from 7c04c1f to c8f8405 Compare June 25, 2018 14:25
@Sunderlandkyl
Copy link
Member Author

Any other changes to make here?

@jcfr
Copy link
Member

jcfr commented Jun 25, 2018

Unless you plane to use the macro in the core in a follow up commit, could you test the new macros by either adding a new test or extending this one ?

@Sunderlandkyl
Copy link
Member Author

Sure, I'll do that.

@Sunderlandkyl Sunderlandkyl force-pushed the std_vector_xml_macros branch 3 times, most recently from 6d4cb0e to b44573d Compare June 26, 2018 18:06
@Sunderlandkyl
Copy link
Member Author

Sunderlandkyl commented Jun 26, 2018

Macros have been added to vtkMRMLNodeTest1. Vector XML methods are tested in TestReadWriteXMLProperties().

Copy link
Member

@jcfr jcfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test 👍

After addressing few nitpicks, we should be all set.

ss << "<MRMLNode ";
node1->WriteXML(ss, NULL);
ss << " />";
std::string testString = ss.str();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testString is unused

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

NULL };

vtkNew<vtkMRMLNodeTestHelper1> node2;
node2->ReadXMLAttributes(atts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems atts is not used anywhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atts is used in:
node2->ReadXMLAttributes(atts);
To populate the parameters of node2.

node2->ReadXMLAttributes(atts);

if (node1->GetTestingStringVector() != node2->GetTestingStringVector())
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix indent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@jcfr jcfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Will integrate after local build completes

@jcfr
Copy link
Member

jcfr commented Jun 26, 2018

Closing. Integrated in r27266

@jcfr jcfr closed this Jun 26, 2018
@Sunderlandkyl
Copy link
Member Author

Thanks @jcfr!

@Sunderlandkyl Sunderlandkyl deleted the std_vector_xml_macros branch June 27, 2018 13:55
@Sunderlandkyl Sunderlandkyl restored the std_vector_xml_macros branch July 28, 2021 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants