@@ -563,6 +563,55 @@ void loadLandmark(IndexT& landmarkId, sfmData::Landmark& landmark, bpt::ptree& l
563563 }
564564}
565565
566+ void saveSurveyPoints (const sfmData::SurveyPoints& spoints, bpt::ptree& parentTree)
567+ {
568+ for (const auto & [viewId, vPoints]: spoints)
569+ {
570+ bpt::ptree viewTree;
571+
572+ viewTree.put (" viewId" , viewId);
573+
574+ bpt::ptree pointsTree;
575+ for (const auto & point : vPoints)
576+ {
577+ bpt::ptree pointTree;
578+
579+ pointTree.put (" X" , point.point3d .x ());
580+ pointTree.put (" Y" , point.point3d .y ());
581+ pointTree.put (" Z" , point.point3d .z ());
582+ pointTree.put (" u" , point.survey .x ());
583+ pointTree.put (" v" , point.survey .y ());
584+
585+ pointsTree.push_back (std::make_pair (" " , pointTree));
586+ }
587+
588+ viewTree.add_child (" points" , pointsTree);
589+
590+ parentTree.push_back (std::make_pair (" " , viewTree));
591+ }
592+ }
593+
594+ void loadSurveyPoints (sfmData::SurveyPoints& spoints, bpt::ptree& parentTree)
595+ {
596+ for (const bpt::ptree::value_type& viewTree : parentTree.get_child (" " ))
597+ {
598+ IndexT viewId = viewTree.second .get <IndexT>(" viewId" );
599+
600+ for (const bpt::ptree::value_type& pointTree : viewTree.second .get_child (" points" ))
601+ {
602+ sfmData::SurveyPoint p;
603+
604+ p.point3d .x () = pointTree.second .get <double >(" X" );
605+ p.point3d .y () = pointTree.second .get <double >(" Y" );
606+ p.point3d .z () = pointTree.second .get <double >(" Z" );
607+ p.survey .x () = pointTree.second .get <double >(" u" );
608+ p.survey .y () = pointTree.second .get <double >(" v" );
609+
610+ spoints[viewId].push_back (p);
611+ }
612+ }
613+ }
614+
566615bool saveJSON (const sfmData::SfMData& sfmData, const std::string& filename, ESfMData partFlag)
567616{
568617 const Vec3i version = {ALICEVISION_SFMDATAIO_VERSION_MAJOR, ALICEVISION_SFMDATAIO_VERSION_MINOR, ALICEVISION_SFMDATAIO_VERSION_REVISION};
@@ -573,6 +622,7 @@ bool saveJSON(const sfmData::SfMData& sfmData, const std::string& filename, ESfM
573622 const bool saveIntrinsics = (partFlag & INTRINSICS) == INTRINSICS;
574623 const bool saveExtrinsics = (partFlag & EXTRINSICS) == EXTRINSICS;
575624 const bool saveStructure = (partFlag & STRUCTURE) == STRUCTURE;
625+ const bool saveSurveys = (partFlag & SURVEYS) == SURVEYS;
576626 const bool saveFeatures = (partFlag & OBSERVATIONS_WITH_FEATURES) == OBSERVATIONS_WITH_FEATURES;
577627 const bool saveObservations = saveFeatures || ((partFlag & OBSERVATIONS) == OBSERVATIONS);
578628
@@ -687,6 +737,16 @@ bool saveJSON(const sfmData::SfMData& sfmData, const std::string& filename, ESfM
687737 fileTree.add_child (" structure" , structureTree);
688738 }
689739
740+ // surveys
741+ if (saveSurveys)
742+ {
743+ bpt::ptree surveyTree;
744+
745+ saveSurveyPoints (sfmData.getSurveyPoints (), surveyTree);
746+
747+ fileTree.add_child (" surveys" , surveyTree);
748+ }
749+
690750 // write the json file with the tree
691751
692752 bpt::write_json (filename, fileTree);
@@ -709,6 +769,7 @@ bool loadJSON(sfmData::SfMData& sfmData,
709769 const bool loadIntrinsics = (partFlag & INTRINSICS) == INTRINSICS;
710770 const bool loadExtrinsics = (partFlag & EXTRINSICS) == EXTRINSICS;
711771 const bool loadStructure = (partFlag & STRUCTURE) == STRUCTURE;
772+ const bool loadSurveys = (partFlag & SURVEYS) == SURVEYS;
712773 const bool loadFeatures = (partFlag & OBSERVATIONS_WITH_FEATURES) == OBSERVATIONS_WITH_FEATURES;
713774 const bool loadObservations = loadFeatures || ((partFlag & OBSERVATIONS) == OBSERVATIONS);
714775
@@ -881,6 +942,15 @@ bool loadJSON(sfmData::SfMData& sfmData,
881942 }
882943 }
883944
945+ // surveyx
946+ if (loadSurveys && fileTree.count (" surveys" ))
947+ {
948+ sfmData::SurveyPoints& surveyPoints = sfmData.getSurveyPoints ();
949+
950+ loadSurveyPoints (surveyPoints, fileTree.get_child (" surveys" ));
951+ }
952+
953+
884954 return true ;
885955}
886956
0 commit comments