Open hucancode opened 8 years ago
AABB tree are quite difficult to serialize in general.
Most of the issues in serialization are pointers. Depending on the type of primitives, the primitives can contains their own data, or be just a pointer to something. In the later case, you need to serialize/deserialize also the external data.
But let's assume, for the moment, that the primitives do not refer to external data...
For the serialization of nodes, I would first substract tree.root_node()
to all m_p_left_child
and m_p_right_child
, and, after the read in the deserialization, add tree.root_node()
to all of them. That would avoid the part ExpandNode
of your code after the deserialization.
In your code, there is another error, about the memory allocation in the deserialization: raw_data
is allocated but never deallocated.
@sloriot The problem is quite interesting, and could be reused in CGAL.
Without being familiar with this topic, we should maybe also have a look at what boost.org offers for serialization.
Boost Serialization seems a good library. Should we try to make CGAL objects compatible with it?
For all CGAL objects of the kernel, in the C3/H3 versions, we should add a new method template:
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & base;
}
and then in the global objects like: CGAL::Point_3
:
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & boost::serialization::base_object<Rep>(*this);
}
http://www.boost.org/doc/libs/1_60_0/libs/serialization/doc/
Thank Irineau for your suggestion. I'm glad you concern this matter. However, let alone these silly error (memory allocation, unoptimized save/load), can you please point out which data/field did i miss in the code above. m_primitives or m_p_nodes? I assume that:
Is it right?
@lrineau any idea on the latest question?
@hucancode Without seeing the type the Primitive
(and more generally the full type of the AABB tree), I cannot tell. As I said earlier, in https://github.com/CGAL/cgal/issues/993#issuecomment-207445545, most of our Primitive
types are not self-contained, and contain pointers to memory in the heap. If that was the case, just writing-reading the raw data will just lead to invalid pointers, pointing to random memory, whereas a proper serialization code would also serialize the pointed objects, and convert pointers to indices.
The AABB-tree being now movable (internal pointers are now gone), this feature should be easier to address if someone is interested in it.
Hello. Has there been any progress or workaround on this? I have a similar problem.
Hello, i am working with AABB Tree. Thanks to CGAL we can handle the intersection very easy. But we had some difficult building the tree. There are about > 1M tris on our (static) scene. Build process usually take several minutes to finish. I am thinking of building AABB Tree once, then serialize them into file. From then i load the file instead of build the whole tree. I wonder if it would be supported in the future or not? Here is my serialize/deserialize naive implementation. It didn't work. If you had interest, drop me some hint, i would appreciate it much.