22 #include <vtkCenterOfMass.h> 23 #include <vtkDoubleArray.h> 25 #include <vtkPointData.h> 26 #include <vtkSmartPointer.h> 27 #include <vtkUnstructuredGrid.h> 29 bool compare(std::pair<double, int> i, std::pair<double, int> j)
31 return (i.first > j.first);
54 m_UseDistances = status;
59 m_NumberOfClustersToUse = num;
74 return m_ProposedPlaneInfo;
80 std::vector<std::pair<double, int>> avgDistances;
83 std::vector<std::pair<int, int>> sizeIDs;
85 for (
unsigned int i = 0; i < m_Grids.size(); i++)
88 vtkSmartPointer<vtkDoubleArray> data =
89 dynamic_cast<vtkDoubleArray *
>(cluster->GetVtkUnstructuredGrid()->GetPointData()->GetArray(0));
91 for (
int j = 0; j < data->GetSize(); j++)
93 avg += data->GetValue(j);
95 avgDistances.push_back(std::make_pair(avg / static_cast<double>(data->GetSize()), i));
99 for (
unsigned int i = 0; i < m_Grids.size(); i++)
101 sizeIDs.push_back(std::make_pair(m_Grids.at(i)->GetVtkUnstructuredGrid()->GetNumberOfPoints(), i));
108 std::sort(sizeIDs.begin(), sizeIDs.end(),
compare);
109 std::sort(avgDistances.begin(), avgDistances.end(),
compare);
111 if (m_Grids.size() < m_NumberOfClustersToUse || m_UseLeastSquares)
114 m_NumberOfClustersToUse = m_Grids.size();
115 m_ProposedPlaneInfo = this->CreatePlaneByLeastSquares(sizeIDs, avgDistances);
119 m_ProposedPlaneInfo = this->CreatePlaneByCentroids(sizeIDs, avgDistances);
122 if (m_SNC.IsNotNull())
124 m_SNC->ReorientSlices(m_SNC->GetCurrentPlaneGeometry()->GetCenter(), m_ProposedPlaneInfo.
x, m_ProposedPlaneInfo.
y);
125 m_SNC->SelectSliceByPoint(m_ProposedPlaneInfo.
pointOnPlane);
130 const std::vector<std::pair<int, int>> &sizeIDs,
const std::vector<std::pair<double, int>> &avgDistances)
132 for (
unsigned int j = 0; j < m_NumberOfClustersToUse; j++)
136 vtkSmartPointer<vtkUnstructuredGrid> tmpGrid;
139 tmpGrid = m_Grids.at(avgDistances.at(j).second)->GetVtkUnstructuredGrid();
141 tmpGrid = m_Grids.at(sizeIDs.at(j).second)->GetVtkUnstructuredGrid();
144 vtkCenterOfMass::ComputeCenterOfMass(tmpGrid->GetPoints(),
nullptr, tmpCenter);
145 std::array<double, 3> center;
146 center[0] = tmpCenter[0];
147 center[1] = tmpCenter[1];
148 center[2] = tmpCenter[2];
149 m_Centroids[j] = center;
153 x[0] = m_Centroids[1][0] - m_Centroids[0][0];
154 x[1] = m_Centroids[1][1] - m_Centroids[0][1];
155 x[2] = m_Centroids[1][2] - m_Centroids[0][2];
157 y[0] = m_Centroids[2][0] - m_Centroids[0][0];
158 y[1] = m_Centroids[2][1] - m_Centroids[0][1];
159 y[2] = m_Centroids[2][2] - m_Centroids[0][2];
161 vtkMath::Cross(x, y, normal);
163 planeInfo.
normal = normal;
173 const std::vector<std::pair<int, int>> &sizeIDs,
const std::vector<std::pair<double, int>> &avgDistances)
180 for (
unsigned int j = 0; j < m_NumberOfClustersToUse; j++)
184 vtkSmartPointer<vtkUnstructuredGrid> tmpGrid;
187 tmpGrid = m_Grids.at(avgDistances.at(j).second)->GetVtkUnstructuredGrid();
189 tmpGrid = m_Grids.at(sizeIDs.at(j).second)->GetVtkUnstructuredGrid();
191 for (
int i = 0; i < tmpGrid->GetNumberOfPoints(); i++)
194 point[0] = tmpGrid->GetPoint(i)[0];
195 point[1] = tmpGrid->GetPoint(i)[1];
196 point[2] = tmpGrid->GetPoint(i)[2];
198 pointset->InsertPoint(pointId, point);
203 planeFilter->SetInput(pointset);
204 planeFilter->Update();
208 if (geoData.IsNull())
210 mitkThrow() <<
"GeometryData output from PlaneFit filter is null!";
214 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)