19 #include "ipSegmentation.h"
30 #define ROUND(a) ((a) > 0 ? (int)((a) + 0.5) : -(int)(0.5 - (a)))
36 m_PaintingPixelValue(paintingPixelValue),
63 Superclass::Activated();
66 SizeChanged.Send(m_Size);
67 m_ToolManager->WorkingDataChanged +=
74 if (m_ToolManager->GetDataStorage()->Exists(m_WorkingNode))
75 m_ToolManager->GetDataStorage()->Remove(m_WorkingNode);
76 m_WorkingSlice =
nullptr;
77 m_CurrentPlane =
nullptr;
78 m_ToolManager->WorkingDataChanged -=
81 Superclass::Deactivated();
111 int radius = (m_Size) / 2;
112 float fradius =
static_cast<float>(m_Size) / 2.0f;
120 centerCorrection.Fill(0);
123 bool evenSize = ((m_Size % 2) == 0);
126 centerCorrection[0] += 0.5;
127 centerCorrection[1] += 0.5;
131 std::vector<mitk::Point2D> quarterCycleUpperRight;
132 std::vector<mitk::Point2D> quarterCycleLowerRight;
133 std::vector<mitk::Point2D> quarterCycleLowerLeft;
134 std::vector<mitk::Point2D> quarterCycleUpperLeft;
137 bool curPointIsInside =
true;
139 curPoint[1] = radius;
140 quarterCycleUpperRight.push_back(upperLeft(curPoint));
146 while (curPoint[1] > 0)
149 float curPointX_squared = 0.0f;
150 float curPointY_squared = (curPoint[1] - centerCorrection[1]) * (curPoint[1] - centerCorrection[1]);
151 while (curPointIsInside)
155 curPointX_squared = (curPoint[0] - centerCorrection[0]) * (curPoint[0] - centerCorrection[0]);
156 const float len = sqrt(curPointX_squared + curPointY_squared);
160 curPointIsInside =
false;
163 quarterCycleUpperRight.push_back(upperLeft(curPoint));
166 while (!curPointIsInside)
170 curPointY_squared = (curPoint[1] - centerCorrection[1]) * (curPoint[1] - centerCorrection[1]);
171 const float len = sqrt(curPointX_squared + curPointY_squared);
175 curPointIsInside =
true;
176 quarterCycleUpperRight.push_back(upperLeft(curPoint));
180 if (curPoint[1] <= 0)
189 std::vector<mitk::Point2D>::const_iterator it = quarterCycleUpperRight.begin();
190 while (it != quarterCycleUpperRight.end())
197 quarterCycleLowerRight.push_back(p);
202 quarterCycleLowerLeft.push_back(p);
207 quarterCycleUpperLeft.push_back(p);
214 std::vector<mitk::Point2D>::const_iterator it = quarterCycleUpperRight.begin();
215 while (it != quarterCycleUpperRight.end())
226 quarterCycleLowerRight.push_back(q);
231 q[1] = -1.0f * q[1] + 1;
232 q[0] = -1.0f * q[0] + 1;
233 quarterCycleLowerLeft.push_back(q);
240 quarterCycleUpperLeft.push_back(q);
248 for (
unsigned int i = 0; i < quarterCycleUpperRight.size(); i++)
250 tempPoint[0] = quarterCycleUpperRight[i][0];
251 tempPoint[1] = quarterCycleUpperRight[i][1];
253 contourInImageIndexCoordinates->AddVertex(tempPoint);
256 for (
int i = quarterCycleLowerRight.size() - 1; i >= 0; i--)
258 tempPoint[0] = quarterCycleLowerRight[i][0];
259 tempPoint[1] = quarterCycleLowerRight[i][1];
261 contourInImageIndexCoordinates->AddVertex(tempPoint);
263 for (
unsigned int i = 0; i < quarterCycleLowerLeft.size(); i++)
265 tempPoint[0] = quarterCycleLowerLeft[i][0];
266 tempPoint[1] = quarterCycleLowerLeft[i][1];
268 contourInImageIndexCoordinates->AddVertex(tempPoint);
271 for (
int i = quarterCycleUpperLeft.size() - 1; i >= 0; i--)
273 tempPoint[0] = quarterCycleUpperLeft[i][0];
274 tempPoint[1] = quarterCycleUpperLeft[i][1];
276 contourInImageIndexCoordinates->AddVertex(tempPoint);
279 m_MasterContour = contourInImageIndexCoordinates;
287 if (m_WorkingSlice.IsNull())
294 m_WorkingSlice->GetGeometry()->WorldToIndex(positionEvent->
GetPositionInWorld(), m_LastPosition);
299 if (m_ToolManager->GetDataStorage()->Exists(m_WorkingNode))
300 m_ToolManager->GetDataStorage()->Remove(m_WorkingNode);
301 m_WorkingSlice =
nullptr;
302 m_CurrentPlane =
nullptr;
308 this->m_WorkingNode->SetVisibility(
true);
310 m_LastEventSender = positionEvent->
GetSender();
311 m_LastEventSlice = m_LastEventSender->
GetSlice();
313 m_MasterContour->SetClosed(
true);
314 this->MouseMoved(interactionEvent,
true);
319 MouseMoved(interactionEvent,
false);
324 MouseMoved(interactionEvent,
true);
334 CheckIfCurrentSliceHasChanged(positionEvent);
336 if (m_LastContourSize != m_Size)
338 UpdateContour(positionEvent);
339 m_LastContourSize = m_Size;
345 m_WorkingSlice->GetGeometry()->WorldToIndex(worldCoordinates, indexCoordinates);
347 MITK_DEBUG <<
"Mouse at W " << worldCoordinates << std::endl;
348 MITK_DEBUG <<
"Mouse at I " << indexCoordinates << std::endl;
353 indexCoordinates[0] =
ROUND(indexCoordinates[0]);
354 indexCoordinates[1] =
ROUND(indexCoordinates[1]);
358 indexCoordinates[0] =
ROUND(indexCoordinates[0]);
359 indexCoordinates[1] =
ROUND(indexCoordinates[1]);
363 if (fabs(indexCoordinates[0] - lastPos[0]) >
mitk::eps || fabs(indexCoordinates[1] - lastPos[1]) >
mitk::eps ||
364 fabs(indexCoordinates[2] - lastPos[2]) >
mitk::eps || leftMouseButtonPressed)
366 lastPos = indexCoordinates;
374 MITK_DEBUG <<
"Mouse at C " << indexCoordinates;
379 contour->Expand(timestep + 1);
380 contour->SetClosed(
true, timestep);
387 Point3D point = (*it)->Coordinates;
388 point[0] += indexCoordinates[0];
389 point[1] += indexCoordinates[1];
391 contour->AddVertex(point, timestep);
395 if (leftMouseButtonPressed)
397 const double dist = indexCoordinates.EuclideanDistanceTo(m_LastPosition);
398 const double radius =
static_cast<double>(m_Size) / 2.0;
400 DataNode *workingNode(m_ToolManager->GetWorkingData(0));
412 contour, timestep, m_WorkingSlice, image, m_PaintingPixelValue * activeColor);
414 m_WorkingNode->SetData(m_WorkingSlice);
415 m_WorkingNode->Modified();
426 direction[0] = indexCoordinates[0] - m_LastPosition[0];
427 direction[1] = indexCoordinates[1] - m_LastPosition[1];
428 direction[2] = indexCoordinates[2] - m_LastPosition[2];
430 direction[0] = direction.GetVnlVector().normalize()[0];
431 direction[1] = direction.GetVnlVector().normalize()[1];
432 direction[2] = direction.GetVnlVector().normalize()[2];
435 normal[0] = -1.0 * direction[1];
436 normal[1] = direction[0];
441 vertex[0] = m_LastPosition[0] + (normal[0] * radius);
442 vertex[1] = m_LastPosition[1] + (normal[1] * radius);
444 contour->AddVertex(vertex);
447 vertex[0] = currentPos[0] + (normal[0] * radius);
448 vertex[1] = currentPos[1] + (normal[1] * radius);
450 contour->AddVertex(vertex);
453 vertex[0] = currentPos[0] - (normal[0] * radius);
454 vertex[1] = currentPos[1] - (normal[1] * radius);
456 contour->AddVertex(vertex);
459 vertex[0] = m_LastPosition[0] - (normal[0] * radius);
460 vertex[1] = m_LastPosition[1] - (normal[1] * radius);
462 contour->AddVertex(vertex);
465 m_WorkingNode->SetData(m_WorkingSlice);
466 m_WorkingNode->Modified();
473 this->m_WorkingNode->SetVisibility(
false);
476 m_LastPosition = indexCoordinates;
480 displayContour->Clear();
491 Point3D point = (*it)->Coordinates;
493 displayContour->AddVertex(point, timestep);
497 m_FeedbackContourNode->GetData()->Modified();
511 this->WriteBackSegmentationResult(positionEvent, m_WorkingSlice->Clone());
514 m_WorkingNode->SetVisibility(
false);
525 if (m_PaintingPixelValue == 1)
527 m_PaintingPixelValue = 0;
530 else if (m_PaintingPixelValue == 0)
532 m_PaintingPixelValue = 1;
543 DataNode *workingNode(m_ToolManager->GetWorkingData(0));
550 if (!image || !planeGeometry || abstractTransformGeometry)
553 if (m_CurrentPlane.IsNull() || m_WorkingSlice.IsNull())
557 m_WorkingNode->ReplaceProperty(
"color", workingNode->GetProperty(
"color"));
558 m_WorkingNode->SetData(m_WorkingSlice);
562 bool isSameSlice(
false);
564 m_CurrentPlane->GetIndexToWorldTransform()->GetMatrix());
566 m_CurrentPlane->GetIndexToWorldTransform()->GetOffset());
569 m_ToolManager->GetDataStorage()->Remove(m_WorkingNode);
570 m_CurrentPlane =
nullptr;
571 m_WorkingSlice =
nullptr;
572 m_WorkingNode =
nullptr;
580 m_WorkingNode->SetData(m_WorkingSlice);
587 if (!m_ToolManager->GetDataStorage()->Exists(m_WorkingNode))
590 m_WorkingNode->SetProperty(
"color", workingNode->GetProperty(
"color"));
595 m_WorkingNode->SetVisibility(
598 m_ToolManager->GetDataStorage()->Add(m_WorkingNode);
606 m_WorkingSlice =
nullptr;
Super class for all position events.
virtual unsigned int GetSlice() const
BaseRenderer * GetSender() const
bool MatrixEqualElementWise(const vnl_matrix_fixed< TCoordRep, NRows, NCols > &matrix1, const vnl_matrix_fixed< TCoordRep, NRows, NCols > &matrix2, mitk::ScalarType epsilon=mitk::eps)
Check for element-wise matrix equality with a user defined accuracy.
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
static vtkRenderWindow * GetRenderWindowByName(const std::string &name)
static void FillContourInSlice(ContourModel *projectedContour, Image *sliceImage, mitk::Image::Pointer workingImage, int paintingPixelValue=1)
Fill a contour in a 2D slice with a specified pixel value at time step 0.
Point3D GetPositionInWorld() const
mitk::ContourElement::VertexIterator VertexIterator
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
The LevelWindow class Class to store level/window values.
static RenderingManager * GetInstance()
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
Image class for storing images.
mitk::Label * GetActiveLabel(unsigned int layer=0)
Returns the active label of a specific layer.
virtual unsigned int GetTimeStep() const
void RequestUpdate(vtkRenderWindow *renderWindow)
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
LabelSetImage class for handling labels and layers in a segmentation session.
MITKCORE_EXPORT const ScalarType eps
Describes a two-dimensional, rectangular plane.
#define CONNECT_FUNCTION(a, f)
unsigned int GetActiveLayer() const
Gets the ID of the currently active layer.
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
Class for nodes of the DataTree.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.