Saving intermediate states to files

Hey everyone.

Super excited about this forum. I’ve messaged support before on this and I’m told a solution is under way, but I figured I could start a thread and help other people that might have the same issue.

I’m trying to save out the data to file/blob data after the initial alignment as well as after the model is generated.

Currently some of the classes have a SaveToStream function but not all of them have a CreateFromStream equivalent.
Figured I’d make a post so I can keep track of the development.

Thanks for the great SDK!

Greetings.

Some data shall be loadable by other means than with a CreateFromFile() function.

Please, which classes do You consider to be missing the aforementioned function and what data do You want to load again? Are they actually needed somewhere down the reconstruction process?

Thank You.

Hello,

Currently I’m trying to split up the process into 2 steps, alignment (outputs sparse cloud) and meshing (outputs a model). I’m planning on adding the third process (texturing) after I figure out the things mentioned in the other thread

Current I’m extending the CreateModel function from the examples, which takes as input

spCache,
spConfig,
spSfm,
spSfmReconstruction

I’m not sure if I create a new cache object it’ll be OK or if it needs the data generated at the CreateHierarchicalSfmPipeline step.

But the other 3 classes I seem to need to be able to serialize and deserialize.

Thanks for your help!

PS: When I get to the TextureModel part (I’ll likely do the simplifcation myself) I’ll need spCache, spSfm, and spSfmReconstruction, as well as a IMvsModel which ideally I can create in memory

Hi Luiz.

spCache holds both unimportant metadata and sometimes actual result data after a process is completed. The cache is stored on disk and if You would delete it between distinct processing steps, metadata could be produced again. But e.g. to save (Mvs)Model, it’s data files have to be relocated with IResourceCache->Relocate() out from the cache, i.e. saved. Also see Clear Cache.

spConfig holds configuration setup. If a particular configuration option is not set up, the default value will be used. The structure is required to be present in the pipeline, thus You can not send NULL. Otherwise, I think the IConfig in the MeshingExample is empty. The IConfig interface does not allow blind iteration over it’s elements, one has to know the keys present. If You are not using it, You can always create a new empty instance. Or You can write a wrapper.

spSfm can be created again, having added the same image files in the same order (important!) and set the SfmReconstructions from the last state, it would be restored. See the functions in IStructureFromMotion commented with // continue. So You actually need to be able to save/load SfmReconstruction.

spSfmReconstruction has both SaveToStream() and CreateFromStream() equivalents. See CreateSfmReconstructionFromFile().

Hey CR

Thanks for that explanation!

I guess my last question would be for an example of using the SaveToStream to write out a spSfmReconstruction to a file.

Thanks for all the help, this gets me a lot closer. Sucks that it has such a requirements on writing things out to disk, but I can work around it

Luiz

I managed to get the stream to be saved out to a file, but CreateSfmReconstructionFromFile returns with E_FAIL.

What’s the best way to debug what is going on?

Hello Luiz.

Not sure what causes the E_FAIL error in your project. The following two functions for saving and loading of sfm reconstructions should work.

Code:
HRESULT SaveSfmReconstruction( CapturingReality::Sfm::ISfmReconstruction *pRec, const WCHAR *url )
{
HRESULT hr = S_OK;

CComPtr< IStream > spStream;
hr = SHCreateStreamOnFile( url, STGM_WRITE | STGM_CREATE, &spStream );

if ( SUCCEEDED( hr ) )
{
hr = spRec->SaveToStream( spStream );
}

if ( SUCCEEDED( hr ) )
{
hr = spStream->Commit( STGC_DEFAULT );
}

return hr;
}
Code:
HRESULT LoadSfmReconstruction( const WCHAR *url, CapturingReality::Sfm::ISfmReconstruction **ppRec )
{
HRESULT hr = CapturingReality::Sfm::CreateSfmReconstructionFromFile( url, ppRec );

return hr;
}

Make sure, that you have permission to read and write in the folder you are specifying in the url argument.

Let me know, if this doesn’t work and what error result you are getting.

-Filip

Hey Filip,

A combination of your functions and changing the Character Set to Unicode got me working!

Thanks so much for all your help. If we can solve the Access Denied error I’m fully back in business.

Thanks!