26 #include <vtkCenterOfMass.h>
27 #include <vtkDoubleArray.h>
29 #include <vtkPointData.h>
30 #include <vtkSmartPointer.h>
31 #include <vtkUnstructuredGrid.h>
33 bool compare(std::pair<double, int> i, std::pair<double, int> j)
35 return (i.first > j.first);
58 m_UseDistances = status;
63 m_NumberOfClustersToUse = num;
78 return m_ProposedPlaneInfo;
84 std::vector<std::pair<double, int>> avgDistances;
87 std::vector<std::pair<int, int>> sizeIDs;
89 for (
unsigned int i = 0; i < m_Grids.size(); i++)
92 vtkSmartPointer<vtkDoubleArray> data =
93 dynamic_cast<vtkDoubleArray *
>(cluster->GetVtkUnstructuredGrid()->GetPointData()->GetArray(0));
95 for (
int j = 0; j < data->GetSize(); j++)
97 avg += data->GetValue(j);
99 avgDistances.push_back(std::make_pair(avg / static_cast<double>(data->GetSize()), i));
103 for (
unsigned int i = 0; i < m_Grids.size(); i++)
105 sizeIDs.push_back(std::make_pair(m_Grids.at(i)->GetVtkUnstructuredGrid()->GetNumberOfPoints(), i));
112 std::sort(sizeIDs.begin(), sizeIDs.end(),
compare);
113 std::sort(avgDistances.begin(), avgDistances.end(),
compare);
115 if (m_Grids.size() < m_NumberOfClustersToUse || m_UseLeastSquares)
118 m_NumberOfClustersToUse = m_Grids.size();
119 m_ProposedPlaneInfo = this->CreatePlaneByLeastSquares(sizeIDs, avgDistances);
123 m_ProposedPlaneInfo = this->CreatePlaneByCentroids(sizeIDs, avgDistances);
126 if (m_SNC.IsNotNull())
128 m_SNC->ReorientSlices(m_SNC->GetCurrentPlaneGeometry()->GetCenter(), m_ProposedPlaneInfo.x, m_ProposedPlaneInfo.y);
129 m_SNC->SelectSliceByPoint(m_ProposedPlaneInfo.pointOnPlane);
134 const std::vector<std::pair<int, int>> &sizeIDs,
const std::vector<std::pair<double, int>> &avgDistances)
136 for (
unsigned int j = 0; j < m_NumberOfClustersToUse; j++)
140 vtkSmartPointer<vtkUnstructuredGrid> tmpGrid;
143 tmpGrid = m_Grids.at(avgDistances.at(j).second)->GetVtkUnstructuredGrid();
145 tmpGrid = m_Grids.at(sizeIDs.at(j).second)->GetVtkUnstructuredGrid();
148 vtkCenterOfMass::ComputeCenterOfMass(tmpGrid->GetPoints(), NULL, tmpCenter);
149 std::array<double, 3> center;
150 center[0] = tmpCenter[0];
151 center[1] = tmpCenter[1];
152 center[2] = tmpCenter[2];
153 m_Centroids[j] = center;
157 x[0] = m_Centroids[1][0] - m_Centroids[0][0];
158 x[1] = m_Centroids[1][1] - m_Centroids[0][1];
159 x[2] = m_Centroids[1][2] - m_Centroids[0][2];
161 y[0] = m_Centroids[2][0] - m_Centroids[0][0];
162 y[1] = m_Centroids[2][1] - m_Centroids[0][1];
163 y[2] = m_Centroids[2][2] - m_Centroids[0][2];
165 vtkMath::Cross(x, y, normal);
167 planeInfo.
normal = normal;
177 const std::vector<std::pair<int, int>> &sizeIDs,
const std::vector<std::pair<double, int>> &avgDistances)
184 for (
unsigned int j = 0; j < m_NumberOfClustersToUse; j++)
188 vtkSmartPointer<vtkUnstructuredGrid> tmpGrid;
191 tmpGrid = m_Grids.at(avgDistances.at(j).second)->GetVtkUnstructuredGrid();
193 tmpGrid = m_Grids.at(sizeIDs.at(j).second)->GetVtkUnstructuredGrid();
195 for (
int i = 0; i < tmpGrid->GetNumberOfPoints(); i++)
198 point[0] = tmpGrid->GetPoint(i)[0];
199 point[1] = tmpGrid->GetPoint(i)[1];
200 point[2] = tmpGrid->GetPoint(i)[2];
202 pointset->InsertPoint(pointId, point);
207 planeFilter->SetInput(pointset);
208 planeFilter->Update();
212 if (geoData.IsNull())
214 mitkThrow() <<
"GeometryData output from PlaneFit filter is null!";
218 planeInfo.
normal = plane->GetNormal();
mitk::Point3D pointOnPlane
void SetUseDistances(bool)
If true, the three clusters with the biggest mean distances are used for plane proposal Required the ...
bool compare(std::pair< double, int > i, std::pair< double, int > j)
Encapsulates the geometrical information needed to descripe a PlaneInfo.
void CreatePlaneInfo()
Creates the actual plane proposal.
void SetNumberOfClustersToUse(unsigned int)
Sets the number of the clusters to be used for plane creation (default=3)
void SetSliceNavigationController(itk::SmartPointer< mitk::SliceNavigationController > &snc)
PlaneInfo GetProposedPlaneInfo()
Describes a two-dimensional, rectangular plane.
std::array< std::array< double, 3 >, 3 > GetCentroids()
void SetUnstructuredGrids(std::vector< itk::SmartPointer< mitk::UnstructuredGrid >> &grids)