Skip to content

Commit

Permalink
Merge pull request openigtlink#147 from adamrankin/polydata_c++11_ran…
Browse files Browse the repository at this point in the history
…ge_loops

ENH: Adding support for C++11 range based for loops for polydata message
  • Loading branch information
leochan2009 authored Aug 11, 2017
2 parents 3ec54f7 + 51f0e9b commit 86dcbcd
Show file tree
Hide file tree
Showing 2 changed files with 278 additions and 5 deletions.
210 changes: 209 additions & 1 deletion Source/igtlPolyDataMessage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,75 @@ int PolyDataPointArray::GetPoint(unsigned int id, igtlFloat32 * point)
return 1;
}

/// Implement support for C++11 ranged for loops
std::vector<PolyDataPointArray::Point>::iterator PolyDataPointArray::begin()
{
return m_Data.begin();
}
std::vector<PolyDataPointArray::Point>::iterator PolyDataPointArray::end()
{
return m_Data.end();
}
std::vector<PolyDataPointArray::Point>::const_iterator PolyDataPointArray::begin() const
{
return m_Data.begin();
}
std::vector<PolyDataPointArray::Point>::const_iterator PolyDataPointArray::end() const
{
return m_Data.end();
}

std::vector<PolyDataPointArray::Point>::reverse_iterator PolyDataPointArray::rbegin()
{
return m_Data.rbegin();
}
std::vector<PolyDataPointArray::Point>::reverse_iterator PolyDataPointArray::rend()
{
return m_Data.rend();
}
std::vector<PolyDataPointArray::Point>::const_reverse_iterator PolyDataPointArray::rbegin() const
{
return m_Data.rbegin();
}
std::vector<PolyDataPointArray::Point>::const_reverse_iterator PolyDataPointArray::rend() const
{
return m_Data.rend();
}

/// Implement support for C++11 ranged for loops
std::vector<PolyDataPointArray::Point>::iterator begin(PolyDataPointArray& list)
{
return list.begin();
}
std::vector<PolyDataPointArray::Point>::iterator end(PolyDataPointArray& list)
{
return list.end();
}
std::vector<PolyDataPointArray::Point>::const_iterator begin(const PolyDataPointArray& list)
{
return list.begin();
}
std::vector<PolyDataPointArray::Point>::const_iterator end(const PolyDataPointArray& list)
{
return list.end();
}

std::vector<PolyDataPointArray::Point>::reverse_iterator rbegin(PolyDataPointArray& list)
{
return list.rbegin();
}
std::vector<PolyDataPointArray::Point>::reverse_iterator rend(PolyDataPointArray& list)
{
return list.rend();
}
std::vector<PolyDataPointArray::Point>::const_reverse_iterator rbegin(const PolyDataPointArray& list)
{
return list.rbegin();
}
std::vector<PolyDataPointArray::Point>::const_reverse_iterator rend(const PolyDataPointArray& list)
{
return list.rend();
}

// Description:
// PolyDataCellArray class to pass vertices, lines, polygons, and triangle strips
Expand Down Expand Up @@ -172,7 +241,7 @@ void PolyDataCellArray::AddCell(int n, igtlUint32 * cell)
}
}

void PolyDataCellArray::AddCell(std::list<igtlUint32> cell)
void PolyDataCellArray::AddCell(const Cell& cell)
{
this->m_Data.push_back(cell);
}
Expand Down Expand Up @@ -238,6 +307,75 @@ int PolyDataCellArray::GetCell(unsigned int id, std::list<igtlUint32>& cell)
return 1;
}

/// Implement support for C++11 ranged for loops
std::vector<PolyDataCellArray::Cell>::iterator PolyDataCellArray::begin()
{
return m_Data.begin();
}
std::vector<PolyDataCellArray::Cell>::iterator PolyDataCellArray::end()
{
return m_Data.end();
}
std::vector<PolyDataCellArray::Cell>::const_iterator PolyDataCellArray::begin() const
{
return m_Data.begin();
}
std::vector<PolyDataCellArray::Cell>::const_iterator PolyDataCellArray::end() const
{
return m_Data.end();
}

std::vector<PolyDataCellArray::Cell>::reverse_iterator PolyDataCellArray::rbegin()
{
return m_Data.rbegin();
}
std::vector<PolyDataCellArray::Cell>::reverse_iterator PolyDataCellArray::rend()
{
return m_Data.rend();
}
std::vector<PolyDataCellArray::Cell>::const_reverse_iterator PolyDataCellArray::rbegin() const
{
return m_Data.rbegin();
}
std::vector<PolyDataCellArray::Cell>::const_reverse_iterator PolyDataCellArray::rend() const
{
return m_Data.rend();
}

/// Implement support for C++11 ranged for loops
std::vector<PolyDataCellArray::Cell>::iterator begin(PolyDataCellArray& list)
{
return list.begin();
}
std::vector<PolyDataCellArray::Cell>::iterator end(PolyDataCellArray& list)
{
return list.end();
}
std::vector<PolyDataCellArray::Cell>::const_iterator begin(const PolyDataCellArray& list)
{
return list.begin();
}
std::vector<PolyDataCellArray::Cell>::const_iterator end(const PolyDataCellArray& list)
{
return list.end();
}

std::vector<PolyDataCellArray::Cell>::reverse_iterator rbegin(PolyDataCellArray& list)
{
return list.rbegin();
}
std::vector<PolyDataCellArray::Cell>::reverse_iterator rend(PolyDataCellArray& list)
{
return list.rend();
}
std::vector<PolyDataCellArray::Cell>::const_reverse_iterator rbegin(const PolyDataCellArray& list)
{
return list.rbegin();
}
std::vector<PolyDataCellArray::Cell>::const_reverse_iterator rend(const PolyDataCellArray& list)
{
return list.rend();
}

// Description:
// Attribute class used for passing attribute data
Expand Down Expand Up @@ -418,6 +556,76 @@ int PolyDataAttribute::GetNthData(unsigned int n, igtlFloat32 * data)
return 1;
}

/// Implement support for C++11 ranged for loops
std::vector<igtlFloat32>::iterator PolyDataAttribute::begin()
{
return m_Data.begin();
}
std::vector<igtlFloat32>::iterator PolyDataAttribute::end()
{
return m_Data.end();
}
std::vector<igtlFloat32>::const_iterator PolyDataAttribute::begin() const
{
return m_Data.begin();
}
std::vector<igtlFloat32>::const_iterator PolyDataAttribute::end() const
{
return m_Data.end();
}

std::vector<igtlFloat32>::reverse_iterator PolyDataAttribute::rbegin()
{
return m_Data.rbegin();
}
std::vector<igtlFloat32>::reverse_iterator PolyDataAttribute::rend()
{
return m_Data.rend();
}
std::vector<igtlFloat32>::const_reverse_iterator PolyDataAttribute::rbegin() const
{
return m_Data.rbegin();
}
std::vector<igtlFloat32>::const_reverse_iterator PolyDataAttribute::rend() const
{
return m_Data.rend();
}

/// Implement support for C++11 ranged for loops
std::vector<igtlFloat32>::iterator begin(PolyDataAttribute& list)
{
return list.begin();
}
std::vector<igtlFloat32>::iterator end(PolyDataAttribute& list)
{
return list.end();
}
std::vector<igtlFloat32>::const_iterator begin(const PolyDataAttribute& list)
{
return list.begin();
}
std::vector<igtlFloat32>::const_iterator end(const PolyDataAttribute& list)
{
return list.end();
}

std::vector<igtlFloat32>::reverse_iterator rbegin(PolyDataAttribute& list)
{
return list.rbegin();
}
std::vector<igtlFloat32>::reverse_iterator rend(PolyDataAttribute& list)
{
return list.rend();
}
std::vector<igtlFloat32>::const_reverse_iterator rbegin(const PolyDataAttribute& list)
{
return list.rbegin();
}
std::vector<igtlFloat32>::const_reverse_iterator rend(const PolyDataAttribute& list)
{
return list.rend();
}

// Description:
// PolyDataMessage class implementation
PolyDataMessage::PolyDataMessage()
Expand Down
73 changes: 69 additions & 4 deletions Source/igtlPolyDataMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,40 @@ class IGTLCommon_EXPORT PolyDataPointArray : public Object {
/// Gets the coordinates of the point specified by 'id'
int GetPoint(unsigned int id, igtlFloat32 * point);

/// Implement support for C++11 ranged for loops
std::vector<Point>::iterator begin();
std::vector<Point>::iterator end();
std::vector<Point>::const_iterator begin() const;
std::vector<Point>::const_iterator end() const;

std::vector<Point>::reverse_iterator rbegin();
std::vector<Point>::reverse_iterator rend();
std::vector<Point>::const_reverse_iterator rbegin() const;
std::vector<Point>::const_reverse_iterator rend() const;

private:
/// A list of the points.
std::vector< Point > m_Data;
};

/// Implement support for C++11 ranged for loops
IGTLCommon_EXPORT std::vector<PolyDataPointArray::Point>::iterator begin(PolyDataPointArray& list);
IGTLCommon_EXPORT std::vector<PolyDataPointArray::Point>::iterator end(PolyDataPointArray& list);
IGTLCommon_EXPORT std::vector<PolyDataPointArray::Point>::const_iterator begin(const PolyDataPointArray& list);
IGTLCommon_EXPORT std::vector<PolyDataPointArray::Point>::const_iterator end(const PolyDataPointArray& list);

IGTLCommon_EXPORT std::vector<PolyDataPointArray::Point>::reverse_iterator rbegin(PolyDataPointArray& list);
IGTLCommon_EXPORT std::vector<PolyDataPointArray::Point>::reverse_iterator rend(PolyDataPointArray& list);
IGTLCommon_EXPORT std::vector<PolyDataPointArray::Point>::const_reverse_iterator rbegin(const PolyDataPointArray& list);
IGTLCommon_EXPORT std::vector<PolyDataPointArray::Point>::const_reverse_iterator rend(const PolyDataPointArray& list);

// The PolyDataCellArray class is used to pass vertices, lines, polygons, and triangle strips
class IGTLCommon_EXPORT PolyDataCellArray : public Object {

public:

typedef std::list<igtlUint32> Cell;

enum {
NULL_POINT = 0xFFFFFFFF,
};
Expand Down Expand Up @@ -211,7 +235,7 @@ class IGTLCommon_EXPORT PolyDataCellArray : public Object {
void AddCell(int n, igtlUint32 * cell);

/// Adds an array of cells stored in 'cell'.
void AddCell(std::list<igtlUint32> cell);
void AddCell(const Cell& cell);

/// GetTotalSize() returns the total memory size of the cell data array in
/// POLYDATA message. Cell data array is array of cell data, consisting of
Expand All @@ -232,13 +256,34 @@ class IGTLCommon_EXPORT PolyDataCellArray : public Object {
int GetCell(unsigned int id, igtlUint32 * cell);

/// Gets the cell specified by the 'id'. A list of points in the cell will be stored in the 'cell'.
int GetCell(unsigned int id, std::list<igtlUint32>& cell);
int GetCell(unsigned int id, Cell& cell);

/// Implement support for C++11 ranged for loops
std::vector<Cell>::iterator begin();
std::vector<Cell>::iterator end();
std::vector<Cell>::const_iterator begin() const;
std::vector<Cell>::const_iterator end() const;

std::vector<Cell>::reverse_iterator rbegin();
std::vector<Cell>::reverse_iterator rend();
std::vector<Cell>::const_reverse_iterator rbegin() const;
std::vector<Cell>::const_reverse_iterator rend() const;

private:
/// A lists of the cells. Each cell consists of multiple points.
std::vector< std::list<igtlUint32> > m_Data;
std::vector<Cell> m_Data;
};

/// Implement support for C++11 ranged for loops
IGTLCommon_EXPORT std::vector<PolyDataCellArray::Cell>::iterator begin(PolyDataCellArray& list);
IGTLCommon_EXPORT std::vector<PolyDataCellArray::Cell>::iterator end(PolyDataCellArray& list);
IGTLCommon_EXPORT std::vector<PolyDataCellArray::Cell>::const_iterator begin(const PolyDataCellArray& list);
IGTLCommon_EXPORT std::vector<PolyDataCellArray::Cell>::const_iterator end(const PolyDataCellArray& list);

IGTLCommon_EXPORT std::vector<PolyDataCellArray::Cell>::reverse_iterator rbegin(PolyDataCellArray& list);
IGTLCommon_EXPORT std::vector<PolyDataCellArray::Cell>::reverse_iterator rend(PolyDataCellArray& list);
IGTLCommon_EXPORT std::vector<PolyDataCellArray::Cell>::const_reverse_iterator rbegin(const PolyDataCellArray& list);
IGTLCommon_EXPORT std::vector<PolyDataCellArray::Cell>::const_reverse_iterator rend(const PolyDataCellArray& list);

/// Attribute class used for passing attribute data.
class IGTLCommon_EXPORT PolyDataAttribute : public Object {
Expand Down Expand Up @@ -316,8 +361,18 @@ class IGTLCommon_EXPORT PolyDataAttribute : public Object {
/// Gets the Nth data.
int GetNthData(unsigned int n, igtlFloat32 * data);

private:
/// Implement support for C++11 ranged for loops
std::vector<igtlFloat32>::iterator begin();
std::vector<igtlFloat32>::iterator end();
std::vector<igtlFloat32>::const_iterator begin() const;
std::vector<igtlFloat32>::const_iterator end() const;

std::vector<igtlFloat32>::reverse_iterator rbegin();
std::vector<igtlFloat32>::reverse_iterator rend();
std::vector<igtlFloat32>::const_reverse_iterator rbegin() const;
std::vector<igtlFloat32>::const_reverse_iterator rend() const;

private:
/// The attribute type.
igtlUint8 m_Type;

Expand All @@ -335,6 +390,16 @@ class IGTLCommon_EXPORT PolyDataAttribute : public Object {

};

/// Implement support for C++11 ranged for loops
IGTLCommon_EXPORT std::vector<igtlFloat32>::iterator begin(PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::iterator end(PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::const_iterator begin(const PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::const_iterator end(const PolyDataAttribute& list);

IGTLCommon_EXPORT std::vector<igtlFloat32>::reverse_iterator rbegin(PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::reverse_iterator rend(PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::const_reverse_iterator rbegin(const PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::const_reverse_iterator rend(const PolyDataAttribute& list);

/// A class for the POLYDATA message type.
class IGTLCommon_EXPORT PolyDataMessage: public MessageBase
Expand Down

0 comments on commit 86dcbcd

Please sign in to comment.