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:daphne.wall...@hrv-simulation.com] 
Sent: Donnerstag, 16. März 2017 12:08
To: mitk-users@lists.sourceforge.net
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é

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();



--
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
mitk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mitk-users

------------------------------------------------------------------------------
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
mitk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to