Skip to content
Snippets Groups Projects
Commit 533afda5 authored by Scott Wittenburg's avatar Scott Wittenburg
Browse files

Provide unique id for vtk objects based on memory address

This change allows us to keep track of vtk objects when exporting
a scene description.  It relies on the fact that the memory address
of objects does not change frequently, if ever.
parent cb8edffd
No related branches found
No related tags found
No related merge requests found
vtk_add_test_python(
TestDataEncoder.py
)
vtk_add_test_python(
NO_DATA NO_VALID NO_OUTPUT
TestObjectId.py
)
from vtkWebCorePython import vtkWebApplication
import vtk
from vtk.test import Testing
class TestObjectId(Testing.vtkTest):
def testObjId(self):
objId1 = vtkWebApplication.GetObjectId(None)
self.assertEqual(objId1, '0')
polyData = vtk.vtkPolyData()
objId2 = vtkWebApplication.GetObjectId(polyData)
self.assertEqual(objId2.index('0x'), 0)
points = polyData.GetPoints()
objId3 = vtkWebApplication.GetObjectId(points)
self.assertEqual(objId3, '0')
if __name__ == "__main__":
Testing.main([(TestObjectId, 'test')])
......@@ -442,3 +442,12 @@ vtkObjectIdMap* vtkWebApplication::GetObjectIdMap()
{
return this->Internals->ObjectIdMap.GetPointer();
}
//----------------------------------------------------------------------------
const char* vtkWebApplication::GetObjectId(vtkObject* obj)
{
std::ostringstream oss;
oss << std::hex << static_cast<void*>(obj);
std::string str = oss.str();
return str.c_str();
}
......@@ -116,6 +116,14 @@ public:
vtkObjectIdMap* GetObjectIdMap();
/**
* Return a hexadecimal formatted string of the VTK object's memory address,
* useful for uniquely identifying the object when exporting data.
*
* e.g. 0x8f05a90
*/
static const char* GetObjectId(vtkObject* obj);
protected:
vtkWebApplication();
~vtkWebApplication();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment