Skip to content
Snippets Groups Projects
Commit e6f5918b authored by Sebastien Jourdain's avatar Sebastien Jourdain Committed by Kitware Robot
Browse files

Merge topic 'vtkweb-add-object-id-method'


533afda5 Provide unique id for vtk objects based on memory address

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !2674
parents a7c39198 533afda5
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