comparison UnitTestsSources/UnitTestsMain.cpp @ 1487:75ac66d5f4b2 bgo-timing-tests

Added timing test for dose loading and histogram computation
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 09 Jun 2020 09:50:03 +0200
parents cde379b9d1d2
children
comparison
equal deleted inserted replaced
1454:faaff0a1711e 1487:75ac66d5f4b2
24 #include "../Framework/StoneInitialization.h" 24 #include "../Framework/StoneInitialization.h"
25 #include "../Framework/Toolbox/FiniteProjectiveCamera.h" 25 #include "../Framework/Toolbox/FiniteProjectiveCamera.h"
26 #include "../Framework/Toolbox/GeometryToolbox.h" 26 #include "../Framework/Toolbox/GeometryToolbox.h"
27 #include "../Framework/Volumes/ImageBuffer3D.h" 27 #include "../Framework/Volumes/ImageBuffer3D.h"
28 #include "../Framework/Loaders/LoaderCache.h" 28 #include "../Framework/Loaders/LoaderCache.h"
29 #include "../Framework/Loaders/OrthancMultiframeVolumeLoader.h"
29 30
30 #include <Core/HttpClient.h> 31 #include <Core/HttpClient.h>
31 #include <Core/Images/ImageProcessing.h> 32 #include <Core/Images/ImageProcessing.h>
32 #include <Core/Logging.h> 33 #include <Core/Logging.h>
33 #include <Core/MultiThreading/SharedMessageQueue.h> 34 #include <Core/MultiThreading/SharedMessageQueue.h>
35 36
36 #include <boost/lexical_cast.hpp> 37 #include <boost/lexical_cast.hpp>
37 #include <boost/date_time/posix_time/posix_time.hpp> 38 #include <boost/date_time/posix_time/posix_time.hpp>
38 #include <boost/thread/thread.hpp> 39 #include <boost/thread/thread.hpp>
39 #include <boost/math/special_functions/round.hpp> 40 #include <boost/math/special_functions/round.hpp>
41 #include "Framework/Loaders/GenericLoadersContext.h"
40 42
41 43
42 TEST(GeometryToolbox, Interpolation) 44 TEST(GeometryToolbox, Interpolation)
43 { 45 {
44 using namespace OrthancStone::GeometryToolbox; 46 using namespace OrthancStone::GeometryToolbox;
877 OrthancStone::LoaderCache::NormalizeUuid(u); 879 OrthancStone::LoaderCache::NormalizeUuid(u);
878 ASSERT_NE(ref, u); 880 ASSERT_NE(ref, u);
879 } 881 }
880 } 882 }
881 883
884 void LoadRtDoseBlocking(boost::shared_ptr<OrthancStone::OrthancMultiframeVolumeLoader> doseLoader, std::string instanceId)
885 {
886 namespace pt = boost::posix_time;
887
888 // Load RTSTRUCT
889 doseLoader->LoadInstance(instanceId);
890
891 pt::ptime initialTime = pt::second_clock::local_time();
892
893 // Wait for the loading process to complete
894 {
895 bool bContinue(true);
896 while (bContinue)
897 {
898 bContinue = !doseLoader->IsPixelDataLoaded();
899 boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
900
901 {
902 pt::ptime nowTime = pt::second_clock::local_time();
903 pt::time_duration diff = nowTime - initialTime;
904 double seconds = static_cast<double>(diff.total_milliseconds()) * 0.001;
905 std::cout << seconds << " seconds elapsed...\n";
906 if (seconds > 30)
907 {
908 const char* msg = "More than 30 seconds elapsed when waiting for RTSTRUCT... Aborting test :(\n";
909 GTEST_FATAL_FAILURE_(msg);
910 bContinue = false;
911 }
912 }
913 }
914 }
915 }
916
917 static void InitializeLoadersContext(const char* orthancApiUrl, OrthancStone::ILoadersContext& loadersContext)
918 {
919 Orthanc::WebServiceParameters p;
920
921 OrthancStone::GenericLoadersContext& typedLoadersContext =
922 dynamic_cast<OrthancStone::GenericLoadersContext&>(loadersContext);
923 // Default is http://localhost:8042
924 // Here's how you may change it
925 p.SetUrl(orthancApiUrl);
926 p.SetCredentials("orthanc", "orthanc");
927 typedLoadersContext.SetOrthancParameters(p);
928
929 typedLoadersContext.StartOracle();
930 }
931
932 void ExitializeLoadersContext(OrthancStone::ILoadersContext& loadersContext)
933 {
934 OrthancStone::GenericLoadersContext& typedLoadersContext =
935 dynamic_cast<OrthancStone::GenericLoadersContext&>(loadersContext);
936
937 typedLoadersContext.StopOracle();
938 }
939
940 TEST(DoseLoader, DISABLED_DoseLoadingTiming)
941 {
942 using namespace OrthancStone;
943
944 // create loaders context
945 std::unique_ptr<OrthancStone::ILoadersContext> loadersContext(new GenericLoadersContext(1,4,1));
946 InitializeLoadersContext("http://localhost:8042/", *loadersContext);
947
948 auto doseVolume = boost::make_shared<DicomVolumeImage>();
949 auto doseLoader = OrthancMultiframeVolumeLoader::Create(*loadersContext, doseVolume);
950
951 LoadRtDoseBlocking(doseLoader, "830a69ff-8e4b5ee3-b7f966c8-bccc20fb-d322dceb");
952
953
954 std::map<std::string,uint64_t> timing = doseLoader->GetTimingInfo();
955
956 for (std::map<std::string, uint64_t>::iterator it = timing.begin(); it != timing.end(); ++it)
957 {
958 const std::string& checkPtName = it->first;
959 uint64_t value = it->second;
960 double valueSec = static_cast<double>(value)/1000000.0;
961 std::cout << checkPtName << " : " << value << " usec (" << valueSec << " secs)" << std::endl;
962 }
963
964 //auto ti = doseLoader->GetTimingInfo();
965
966 //Register<DicomVolumeImage::ContentUpdatedMessage>(*doseLoader_, &RtViewerApp::HandleDoseLoaded);
967 ExitializeLoadersContext(*loadersContext);
968 }
969
970
882 int main(int argc, char **argv) 971 int main(int argc, char **argv)
883 { 972 {
884 Orthanc::Logging::Initialize(); 973 Orthanc::Logging::Initialize();
885 Orthanc::Logging::EnableInfoLevel(true); 974 Orthanc::Logging::EnableInfoLevel(true);
886 975