# HG changeset patch # User Sebastien Jodogne # Date 1558603657 -7200 # Node ID 53167294d870de84a090a3965a4edd76e67d16f9 # Parent 26f4345e771e1895c5f669262c2e84ddc4d3d01e# Parent 07adcffba38c344a726a91a09dad7a68643f9ab7 merge diff -r 26f4345e771e -r 53167294d870 Framework/Scene2DViewport/LayerHolder.h --- a/Framework/Scene2DViewport/LayerHolder.h Thu May 23 11:27:11 2019 +0200 +++ b/Framework/Scene2DViewport/LayerHolder.h Thu May 23 11:27:37 2019 +0200 @@ -17,54 +17,54 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . **/ - -#pragma once - -#include "PointerTypes.h" -#include "boost/noncopyable.hpp" + +#pragma once + +#include "PointerTypes.h" +#include "boost/noncopyable.hpp" namespace OrthancStone { class PolylineSceneLayer; class TextSceneLayer; - /** - This class holds the indices of a set a layer and supplies - getters to the concrete layer objects. Sounds very ad hoc, and it is. - */ - class LayerHolder : public boost::noncopyable - { - public: - /** - This ctor merely stores the scene and layer counts. No layer creation - performed at this time - */ - LayerHolder( - ViewportControllerWPtr controllerW, - int polylineLayerCount, int textLayerCount); - - /** - This actually creates the layers - */ + /** + This class holds the indices of a set a layer and supplies + getters to the concrete layer objects. Sounds very ad hoc, and it is. + */ + class LayerHolder : public boost::noncopyable + { + public: + /** + This ctor merely stores the scene and layer counts. No layer creation + performed at this time + */ + LayerHolder( + ViewportControllerWPtr controllerW, + int polylineLayerCount, int textLayerCount); + + /** + This actually creates the layers + */ void CreateLayers(); - - /** - This creates the layers if they are not created yet. Can be useful in - some scenarios - */ - void CreateLayersIfNeeded(); - - /** - Whether the various text and polylines layers have all been created or - none at all - */ - bool AreLayersCreated() const; - + + /** + This creates the layers if they are not created yet. Can be useful in + some scenarios + */ + void CreateLayersIfNeeded(); + + /** + Whether the various text and polylines layers have all been created or + none at all + */ + bool AreLayersCreated() const; + /** This removes the layers from the scene */ void DeleteLayers(); - + /** Please note that the returned pointer belongs to the scene.Don't you dare storing or deleting it, you fool! @@ -92,7 +92,7 @@ int polylineLayerCount_; ViewportControllerWPtr controllerW_; int baseLayerIndex_; - }; + }; typedef boost::shared_ptr LayerHolderPtr; } diff -r 26f4345e771e -r 53167294d870 Framework/Scene2DViewport/ViewportController.cpp --- a/Framework/Scene2DViewport/ViewportController.cpp Thu May 23 11:27:11 2019 +0200 +++ b/Framework/Scene2DViewport/ViewportController.cpp Thu May 23 11:27:37 2019 +0200 @@ -128,9 +128,9 @@ { ORTHANC_ASSERT(std::find(measureTools_.begin(), measureTools_.end(), measureTool) != measureTools_.end(), "Measure tool not found"); - measureTools_.erase( - std::remove(measureTools_.begin(), measureTools_.end(), measureTool), - measureTools_.end()); + measureTools_.erase( + std::remove(measureTools_.begin(), measureTools_.end(), measureTool), + measureTools_.end()); } } diff -r 26f4345e771e -r 53167294d870 Framework/StoneException.h --- a/Framework/StoneException.h Thu May 23 11:27:11 2019 +0200 +++ b/Framework/StoneException.h Thu May 23 11:27:37 2019 +0200 @@ -134,7 +134,7 @@ # define ORTHANC_EXPAND( x ) x -# define GET_ORTHANC_ASSERT(_1,_2,NAME,...) NAME +# define GET_ORTHANC_ASSERT(_1,_2,NAME,...) NAME # define ORTHANC_ASSERT(...) ORTHANC_EXPAND(GET_ORTHANC_ASSERT(__VA_ARGS__, ORTHANC_ASSERT2, ORTHANC_ASSERT1, UNUSED)(__VA_ARGS__)) /* @@ -152,9 +152,9 @@ Note: ORTHANC_EXPAND is required for some older compilers (MS v100 cl.exe ) */ - - - - - - + + + + + + diff -r 26f4345e771e -r 53167294d870 Samples/Sdl/Loader.cpp --- a/Samples/Sdl/Loader.cpp Thu May 23 11:27:11 2019 +0200 +++ b/Samples/Sdl/Loader.cpp Thu May 23 11:27:37 2019 +0200 @@ -382,9 +382,10 @@ const DicomInstanceParameters& parameters = *slices_[0]; image_.reset(new ImageBuffer3D(parameters.GetExpectedPixelFormat(), - parameters.GetImageInformation().GetWidth(), - parameters.GetImageInformation().GetHeight(), - slices.GetSlicesCount(), false /* don't compute range */)); + parameters.GetImageInformation().GetWidth(), + parameters.GetImageInformation().GetHeight(), + static_cast(slices.GetSlicesCount()), + false /* don't compute range */)); geometry_->SetSize(image_->GetWidth(), image_->GetHeight(), image_->GetDepth()); geometry_->SetAxialGeometry(slices.GetSliceGeometry(0)); @@ -467,7 +468,7 @@ { { ImageBuffer3D::SliceWriter writer - (*image_, VolumeProjection_Axial, index); + (*image_, VolumeProjection_Axial, static_cast(index)); Orthanc::ImageProcessing::Copy(writer.GetAccessor(), image); } @@ -571,8 +572,8 @@ if (volume_.GetSlicesCount() != 0) { - strategy_.reset(new BasicFetchingStrategy( - sorter_->CreateSorter(volume_.GetSlicesCount()), BEST_QUALITY)); + strategy_.reset(new BasicFetchingStrategy(sorter_->CreateSorter( + static_cast(volume_.GetSlicesCount())), BEST_QUALITY)); assert(simultaneousDownloads_ != 0); for (unsigned int i = 0; i < simultaneousDownloads_; i++) diff -r 26f4345e771e -r 53167294d870 Samples/Sdl/TrackerSample.cpp --- a/Samples/Sdl/TrackerSample.cpp Thu May 23 11:27:11 2019 +0200 +++ b/Samples/Sdl/TrackerSample.cpp Thu May 23 11:27:37 2019 +0200 @@ -75,7 +75,7 @@ { StoneInitialize(); Orthanc::Logging::EnableInfoLevel(true); - Orthanc::Logging::EnableTraceLevel(true); +// Orthanc::Logging::EnableTraceLevel(true); try { diff -r 26f4345e771e -r 53167294d870 Samples/Sdl/TrackerSampleApp.cpp --- a/Samples/Sdl/TrackerSampleApp.cpp Thu May 23 11:27:11 2019 +0200 +++ b/Samples/Sdl/TrackerSampleApp.cpp Thu May 23 11:27:37 2019 +0200 @@ -71,6 +71,11 @@ return controller_->GetScene(); } + Scene2DConstPtr TrackerSampleApp::GetScene() const + { + return controller_->GetScene(); + } + void TrackerSampleApp::SelectNextTool() { currentTool_ = static_cast(currentTool_ + 1); @@ -153,15 +158,76 @@ GetScene()->DeleteLayer(FLOATING_INFOTEXT_LAYER_ZINDEX); } + ScenePoint2D TrackerSampleApp::GetRandomPointInScene() const + { + unsigned int w = compositor_->GetCanvasWidth(); + LOG(TRACE) << "compositor_->GetCanvasWidth() = " << + compositor_->GetCanvasWidth(); + unsigned int h = compositor_->GetCanvasHeight(); + LOG(TRACE) << "compositor_->GetCanvasHeight() = " << + compositor_->GetCanvasHeight(); + + if ((w >= RAND_MAX) || (h >= RAND_MAX)) + LOG(WARNING) << "Canvas is too big : tools will not be randomly placed"; + + int x = rand() % w; + int y = rand() % h; + LOG(TRACE) << "random x = " << x << "random y = " << y; + + ScenePoint2D p = compositor_->GetPixelCenterCoordinates(x, y); + LOG(TRACE) << "--> p.GetX() = " << p.GetX() << " p.GetY() = " << p.GetY(); + + ScenePoint2D r = p.Apply(GetScene()->GetCanvasToSceneTransform()); + LOG(TRACE) << "--> r.GetX() = " << r.GetX() << " r.GetY() = " << r.GetY(); + return r; + } + + void TrackerSampleApp::CreateRandomMeasureTool() + { + static bool srandCalled = false; + if (!srandCalled) + { + srand(42); + srandCalled = true; + } + + int i = rand() % 2; + LOG(TRACE) << "random i = " << i; + switch (i) + { + case 0: + // line measure + { + CreateLineMeasureCommandPtr cmd = + boost::make_shared( + IObserver::GetBroker(), + controller_, + GetRandomPointInScene()); + cmd->SetEnd(GetRandomPointInScene()); + controller_->PushCommand(cmd); + } + break; + case 1: + // angle measure + { + CreateAngleMeasureCommandPtr cmd = + boost::make_shared( + IObserver::GetBroker(), + controller_, + GetRandomPointInScene()); + cmd->SetCenter(GetRandomPointInScene()); + cmd->SetSide2End(GetRandomPointInScene()); + controller_->PushCommand(cmd); + } + break; + } + } + void TrackerSampleApp::HandleApplicationEvent( const SDL_Event & event) { DisplayInfoText(); - // we seed the random number generator for random measure tool - // generation - srand(42); - if (event.type == SDL_MOUSEMOTION) { int scancodeCount = 0; @@ -192,8 +258,8 @@ //LOG(TRACE) << "event.button.x = " << event.button.x << " " << // "event.button.y = " << event.button.y; - //LOG(TRACE) << "activeTracker_->PointerMove(e); " << - // e.GetMainPosition().GetX() << " " << e.GetMainPosition().GetY(); + LOG(TRACE) << "activeTracker_->PointerMove(e); " << + e.GetMainPosition().GetX() << " " << e.GetMainPosition().GetY(); activeTracker_->PointerMove(e); if (!activeTracker_->IsAlive()) @@ -254,22 +320,20 @@ break; case SDLK_m: - // let's create a random measuring tool - - - + CreateRandomMeasureTool(); + break; case SDLK_s: controller_->FitContent(compositor_->GetCanvasWidth(), compositor_->GetCanvasHeight()); break; case SDLK_z: - LOG(INFO) << "SDLK_z has been pressed. event.key.keysym.mod == " << event.key.keysym.mod; + LOG(TRACE) << "SDLK_z has been pressed. event.key.keysym.mod == " << event.key.keysym.mod; if (event.key.keysym.mod & KMOD_CTRL) { if (controller_->CanUndo()) { - LOG(INFO) << "Undoing..."; + LOG(TRACE) << "Undoing..."; controller_->Undo(); } else @@ -280,12 +344,12 @@ break; case SDLK_y: - LOG(INFO) << "SDLK_y has been pressed. event.key.keysym.mod == " << event.key.keysym.mod; + LOG(TRACE) << "SDLK_y has been pressed. event.key.keysym.mod == " << event.key.keysym.mod; if (event.key.keysym.mod & KMOD_CTRL) { if (controller_->CanRedo()) { - LOG(INFO) << "Redoing..."; + LOG(TRACE) << "Redoing..."; controller_->Redo(); } else diff -r 26f4345e771e -r 53167294d870 Samples/Sdl/TrackerSampleApp.h --- a/Samples/Sdl/TrackerSampleApp.h Thu May 23 11:27:11 2019 +0200 +++ b/Samples/Sdl/TrackerSampleApp.h Thu May 23 11:27:37 2019 +0200 @@ -65,6 +65,7 @@ void DisableTracker(); Scene2DPtr GetScene(); + Scene2DConstPtr GetScene() const; void HandleApplicationEvent(const SDL_Event& event); @@ -77,7 +78,13 @@ private: void SelectNextTool(); + void CreateRandomMeasureTool(); + /** + This returns a random point in the canvas part of the scene, but in + scene coordinates + */ + ScenePoint2D GetRandomPointInScene() const; FlexiblePointerTrackerPtr TrackerHitTest(const PointerEvent& e);