There's not a direct connection between reading planar figures and the 
measurement plugin but the plugin listens to the data manager with its 
implementation of the NodeAdded() method [1]. That's where the plugin sets the 
interactor. The display is completely independent from the plugin, as the 
planar figure mappers are automatically added to the data node as soon as you 
add the node containing the PF to the data storage.

[1] 
https://github.com/MITK/MITK/blob/master/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkMeasurementView.cpp#L261-L283


-----Original Message-----
From: Daphné Wallach [mailto:[email protected]] 
Sent: Donnerstag, 16. März 2017 17:03
To: Dinkelacker, Stefan
Subject: Re: [mitk-users] Displaying a planar figure created from a set of 3D 
points

Dear Stefan,

Thank you for your prompt answer.

I am already using PlaceFigure() for the first control point, and
AddControlPoint() for the subsequent points. Moreover, I do need to add an 
interactor.

Actually, I just realized that what I need to do is close to what is done in 
the "Measurement" plugin, when measures are saved to a file and then loaded 
again. However, I cannot find the relevant classes: the figure points and 
geometry are read in "mitkPlanarFigureReader", but I don't see where the 
interactor is created.

If anyone had any idea about how I could display the figure and interact with 
it, that would be most helpful.

Best regards,

Daphné

Below is a snippet of my code:


        mitk::PlanarFigure::Pointer figure = mitk::PlanarBezierCurve::New();

          // Create node containing the curve, select it and add it to 
datastorage
          mitk::DataNode::Pointer newNode = mitk::DataNode::New();
          newNode->SetData(figure);
          newNode->SetSelected(true);

          if (!_ds->Exists(newNode))
          {
              _ds->Add(newNode);
          }

          // Set new interactor
          mitk::PlanarFigureInteractor::Pointer interactor = 
dynamic_cast<mitk::PlanarFigureInteractor*>(newNode->GetDataInteractor().GetPointer());
          if (interactor.IsNull())
          {
              interactor = mitk::PlanarFigureInteractor::New();
              auto planarFigureModule =
us::ModuleRegistry::GetModule("MitkPlanarFigure");

interactor->LoadStateMachine("PlanarFigureInteraction.xml",
planarFigureModule);
              interactor->SetEventConfig("PlanarFigureConfig.xml",
planarFigureModule);
          }
          interactor->SetDataNode(newNode);

          // Set figure plane geometry
          mitk::PlaneGeometry::Pointer curvePlane = mitk::PlaneGeometry::New();

          mitk::DataNode::Pointer originalImageNode = 
_ds->GetNamedNode("originalImage"); // This node contains a dicom image on 
which we want to draw the planar figure
          mitk::BaseGeometry* originalImageGeometry =
originalImageNode->GetData()->GetGeometry();

          itk::Index<3> idx;
          originalImageGeometry->WorldToIndex(curve.points[0], idx); // the 
"curve" variable contains the 3D control points
          mitk::ScalarType planeZPosition = idx[2];

curvePlane->InitializeStandardPlane(originalImageGeometry,
mitk::PlaneGeometry::Axial, planeZPosition);
          figure->SetPlaneGeometry(curvePlane);

          //Set points to figure
          for (int i = 0; i < curve.points.size(); i++)
          {
              mitk::Point2D indexPoint2d;
              for (int dim = 0; dim < 2; dim++)
              {
                  indexPoint2d[dim] = (curve.points[i][dim] -
originalImageGeometry->GetOrigin()[dim]);
              }
              if (i == 0)
              {
figure->InvokeEvent(mitk::StartPlacementPlanarFigureEvent());
                  figure->PlaceFigure(indexPoint2d);
newNode->SetBoolProperty("PlanarFigureInitializedWindow", true);
              }
              else
              {
                  figure->SetControlPoint(i, indexPoint2d, true);
              }
          }

          figure->EvaluateFeatures();
          figure->DeselectControlPoint();

          // Finalize interaction: when these six lines are commented, the 
figure is displayed when the user clicks on the slice where the figure is placed
          figure->Modified();
          figure->SetProperty("initiallyplaced",
mitk::BoolProperty::New(true));
newNode->SetBoolProperty("planarfigure.drawcontrolpoints", true);
          newNode->Modified();
figure->InvokeEvent(mitk::EndPlacementPlanarFigureEvent());
figure->InvokeEvent(mitk::EndInteractionPlanarFigureEvent());

mitk::RenderingManager::GetInstance()->RequestUpdateAll();


Le 16/03/2017 à 13:18, Dinkelacker, Stefan a écrit :
> Hi, Planar Figures can be a bit tricky when constructing them 
> programmatically. See the Planar Figure tests for examples [1]. The thing is 
> (which I assume you didn't do) that you use the PlaceFigure() method for the 
> first control point and AddControlPoint() for the subsequent control points 
> only. You also do not need to add an interactor, if you do not want the user 
> to modify the planar figure. BTW you can also query if a planar figure is in 
> its "placed" state by calling IsPlaced().
>
> Hope that helps,
> Stefan
>
> [1] https://github.com/MITK/MITK/tree/master/Modules/PlanarFigure/test
>
> -----Original Message-----
> From: Daphné Wallach [mailto:[email protected]]
> Sent: Donnerstag, 16. März 2017 12:08
> To: [email protected]
> Subject: [mitk-users] Displaying a planar figure created from a set of 
> 3D points
>
> Dear MITK users,
>
> I am developping an application using MITK as a library, and I am currently 
> trying to load a planar figure from its 3D control points.
> However, I can only manage to display the figure when I start interacting 
> with it. Otherwise, the figure is not displayed.
>
> Here is the workflow I am using:
>    - create a new figure
>    - create a new node containing the figure, select it, and add to the 
> datastorage
>    - set a planar figure interactor to the node
>    - set the geometry of the figure: the geometry is computed from a dicom 
> image stored in the datastorage. The planar figure is placed on an axial 
> slice of this image.
>    - set the points to the figure
>    - finalize the interaction
>    - update all viewers
>
> When I comment the lines in the "Finalize interaction" part, the figure 
> appears when I click on the viewer at the slice where the figure is (and a 
> new point is added at the click).
>
> I have struggled with this issue for several days now, and I would grealty 
> appreciate any help!
>
> Best regards,
> Daphné
>
>
>
>
> --
> Daphné Wallach
> Ingénieur de recherche
> http://www.hrv-simulation.com
>
>
> ----------------------------------------------------------------------
> -------- Check out the vibrant tech community on one of the world's 
> most engaging tech sites, Slashdot.org! http://sdm.link/slashdot 
> _______________________________________________
> mitk-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mitk-users

--
Daphné Wallach
Ingénieur de recherche
http://www.hrv-simulation.com


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to