libE57Format icon indicating copy to clipboard operation
libE57Format copied to clipboard

E57SimpleWriter: Pass file guid as constructor argument

Open nigels-com opened this issue 3 years ago • 4 comments

In testing we noticed that E57 files are not completely deterministic. Turns out to be due to random GUIDs generated at the file and Data3D scope. This change is necesssary for using a user-specified GUID rather than a randomly generated one at the file scope.

nigels-com avatar Jun 08 '22 05:06 nigels-com

Perhaps a better solution would be to set the RNG seed instead? Then it captures all calls to generateRandomGUID().

Maybe something like:

   static std::random_device rd;
   static std::mt19937 mte( rd() );
   
   void seedRandom( uint32_t inRand )
   {
      mte.seed( inRand );
   }

And then use mte in generateRandomGUID() in place of gen.

Instead of passing a GUID in your changes, pass a seed and call seedRandom() in Writer::Writer(). Then you don't need the changes to WriterImpl either.

asmaloney avatar Jun 08 '22 10:06 asmaloney

That's an option. I think it has some downsides, though.

Technical: making the RNG static has implications for multi-threading and determinism.

Design: I think the intention of the GUID is that they're application-specified, rather than randomised.

Screenshot from 2022-06-08 15-59-40

If we wish to avoid a possibly breaking API change, we could extend the simpler writer API to allow for setting a specific GUID, along similar lines to what we can already do for Data3D?

        e57::Data3D header;
        header.guid = guid;
        header.pointsSize = size;

nigels-com avatar Jun 08 '22 23:06 nigels-com

Thanks Nigel.

So maybe something like this?

   struct E57_DLL WriterOptions
   {
      ustring guid;        //!< A globally unique identification string for the current version of the Image2D object
      ustring coordinateMetadata; //!< Information describing the Coordinate Reference System to be used for the file
   };

// ...

      Writer( const ustring &filePath, const WriterOptions &options );

// ... and

      WriterImpl( const ustring &filePath, const WriterOptions &options );

We can leave the old constructors for compatibility and mark them as deprecated.

asmaloney avatar Jun 13 '22 13:06 asmaloney

Yes, agreed.

nigels-com avatar Jun 13 '22 23:06 nigels-com

Reworked as discussed.

nigels-com avatar Sep 27 '22 10:09 nigels-com

Awesome - thanks Nigel!

asmaloney avatar Sep 27 '22 21:09 asmaloney