23 : m_SegmentationBinaryImage(NULL),
25 m_NegativeNormalCounter(0),
26 m_PositiveNormalCounter(0),
27 m_UseProgressBar(false),
31 this->SetNthOutput(0, output.GetPointer());
40 unsigned int numberOfInputs = this->GetNumberOfIndexedInputs();
43 for (
unsigned int i = 0; i < numberOfInputs; i++)
46 Surface *currentSurface =
const_cast<Surface *
>(this->GetInput(i));
49 vtkSmartPointer<vtkCellArray> existingPolys = polyData->GetPolys();
51 vtkSmartPointer<vtkPoints> existingPoints = polyData->GetPoints();
53 existingPolys->InitTraversal();
55 vtkIdType *cell(NULL);
56 vtkIdType cellSize(0);
60 normals->SetNumberOfComponents(3);
61 normals->SetNumberOfTuples(polyData->GetNumberOfPoints());
65 m_NegativeNormalCounter = 0;
66 m_PositiveNormalCounter = 0;
70 for (existingPolys->InitTraversal(); existingPolys->GetNextCell(cellSize, cell);)
76 double polygonNormal[3] = {0.0};
84 existingPoints->GetPoint(cell[0], p1);
85 unsigned int index = cellSize * 0.5;
86 existingPoints->GetPoint(cell[index], p2);
88 v1[0] = p2[0] - p1[0];
89 v1[1] = p2[1] - p1[1];
90 v1[2] = p2[2] - p1[2];
92 for (vtkIdType k = 2; k < cellSize; k++)
94 index = cellSize * 0.25;
95 existingPoints->GetPoint(cell[index], p1);
96 index = cellSize * 0.75;
97 existingPoints->GetPoint(cell[index], p2);
99 v2[0] = p2[0] - p1[0];
100 v2[1] = p2[1] - p1[1];
101 v2[2] = p2[2] - p1[2];
103 vtkMath::Cross(v1, v2, polygonNormal);
104 if (vtkMath::Norm(polygonNormal) != 0)
112 double vertexNormalTemp[3];
113 existingPoints->GetPoint(cell[0], p1);
114 existingPoints->GetPoint(cell[1], p2);
116 v1[0] = p2[0] - p1[0];
117 v1[1] = p2[1] - p1[1];
118 v1[2] = p2[2] - p1[2];
120 vtkMath::Cross(v1, polygonNormal, vertexNormalTemp);
124 double vertexNormal[3];
126 for (vtkIdType j = 0; j < cellSize - 2; j++)
128 existingPoints->GetPoint(cell[j + 1], p1);
129 existingPoints->GetPoint(cell[j + 2], p2);
131 v1[0] = p2[0] - p1[0];
132 v1[1] = p2[1] - p1[1];
133 v1[2] = p2[2] - p1[2];
135 vtkMath::Cross(v1, polygonNormal, vertexNormal);
139 double finalNormal[3];
141 finalNormal[0] = (vertexNormal[0] + vertexNormalTemp[0]) * 0.5;
142 finalNormal[1] = (vertexNormal[1] + vertexNormalTemp[1]) * 0.5;
143 finalNormal[2] = (vertexNormal[2] + vertexNormalTemp[2]) * 0.5;
147 if (m_SegmentationBinaryImage)
150 worldCoord[0] = p1[0] + finalNormal[0] * m_MaxSpacing;
151 worldCoord[1] = p1[1] + finalNormal[1] * m_MaxSpacing;
152 worldCoord[2] = p1[2] + finalNormal[2] * m_MaxSpacing;
157 m_SegmentationBinaryImage->GetGeometry()->WorldToIndex(worldCoord, idx);
160 if (m_SegmentationBinaryImage->GetImageDescriptor()
161 ->GetChannelDescriptor()
163 .GetComponentType() == itk::ImageIOBase::UCHAR)
168 else if (m_SegmentationBinaryImage->GetImageDescriptor()
169 ->GetChannelDescriptor()
171 .GetComponentType() == itk::ImageIOBase::USHORT)
186 ++m_PositiveNormalCounter;
191 ++m_NegativeNormalCounter;
195 vertexNormalTemp[0] = vertexNormal[0];
196 vertexNormalTemp[1] = vertexNormal[1];
197 vertexNormalTemp[2] = vertexNormal[2];
199 vtkIdType
id = cell[j + 1];
200 normals->SetTuple(
id, finalNormal);
203 existingPoints->GetPoint(cell[0], p1);
204 existingPoints->GetPoint(cell[1], p2);
206 v1[0] = p2[0] - p1[0];
207 v1[1] = p2[1] - p1[1];
208 v1[2] = p2[2] - p1[2];
210 vtkMath::Cross(v1, polygonNormal, vertexNormal);
214 vertexNormal[0] = (vertexNormal[0] + vertexNormalTemp[0]) * 0.5;
215 vertexNormal[1] = (vertexNormal[1] + vertexNormalTemp[1]) * 0.5;
216 vertexNormal[2] = (vertexNormal[2] + vertexNormalTemp[2]) * 0.5;
219 vtkIdType
id = cell[0];
220 normals->SetTuple(
id, vertexNormal);
221 id = cell[cellSize - 1];
222 normals->SetTuple(
id, vertexNormal);
224 if (m_NegativeNormalCounter > m_PositiveNormalCounter)
226 for (vtkIdType n = 0; n < cellSize; n++)
229 normals->GetTuple(offSet + n, normal);
230 normal[0] = (-1) * normal[0];
231 normal[1] = (-1) * normal[1];
232 normal[2] = (-1) * normal[2];
233 normals->SetTuple(offSet + n, normal);
237 m_NegativeNormalCounter = 0;
238 m_PositiveNormalCounter = 0;
244 surface->GetVtkPolyData()->GetCellData()->SetNormals(normals);
248 if (this->m_UseProgressBar)
258 unsigned int idCounter(0);
261 for (
unsigned int i = 0; i < this->GetNumberOfIndexedOutputs(); i++)
263 Surface *currentSurface =
const_cast<Surface *
>(this->GetOutput(i));
266 vtkSmartPointer<vtkDoubleArray> currentCellNormals =
267 vtkDoubleArray::SafeDownCast(polyData->GetCellData()->GetNormals());
269 vtkSmartPointer<vtkCellArray> existingPolys = polyData->GetPolys();
271 vtkSmartPointer<vtkPoints> existingPoints = polyData->GetPoints();
273 existingPolys->InitTraversal();
275 vtkIdType *cell(NULL);
276 vtkIdType cellSize(0);
278 for (existingPolys->InitTraversal(); existingPolys->GetNextCell(cellSize, cell);)
280 for (vtkIdType j = 0; j < cellSize; j++)
282 double currentNormal[3];
283 currentCellNormals->GetTuple(cell[j], currentNormal);
285 line->GetPointIds()->SetNumberOfIds(2);
288 existingPoints->GetPoint(cell[j], p0);
289 newPoint[0] = p0[0] + currentNormal[0];
290 newPoint[1] = p0[1] + currentNormal[1];
291 newPoint[2] = p0[2] + currentNormal[2];
293 line->GetPointIds()->SetId(0, idCounter);
294 newPoints->InsertPoint(idCounter, p0);
297 line->GetPointIds()->SetId(1, idCounter);
298 newPoints->InsertPoint(idCounter, newPoint);
301 newLines->InsertNextCell(line);
306 newPolyData->SetPoints(newPoints);
307 newPolyData->SetLines(newLines);
308 newPolyData->BuildCells();
311 surface->SetVtkPolyData(newPolyData);
318 m_MaxSpacing = maxSpacing;
323 Superclass::GenerateOutputInformation();
328 for (
unsigned int i = 0; i < this->GetNumberOfIndexedInputs(); i++)
330 this->PopBackInput();
332 this->SetNumberOfIndexedInputs(0);
333 this->SetNumberOfIndexedOutputs(0);
336 this->SetNthOutput(0, output.GetPointer());
341 this->m_UseProgressBar = status;
346 this->m_ProgressStepSize = stepSize;
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
Class for storing surfaces (vtkPolyData).
const TPixel & GetPixelByIndexSafe(const itk::Index< VDimension > &idx) const
Gives locked and index-based read access for a particular image part. The class provides several set-...
mitk::Surface::Pointer GetNormalsAsSurface()
virtual vtkPolyData * GetVtkPolyData(unsigned int t=0) const
virtual void GenerateOutputInformation() override
void SetProgressStepSize(unsigned int stepSize)
Set the stepsize which the progress bar should proceed.
virtual ~ComputeContourSetNormalsFilter()
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
void SetUseProgressBar(bool)
Set whether the mitkProgressBar should be used.
ComputeContourSetNormalsFilter()
virtual void GenerateData() override
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
void SetMaxSpacing(double)
void Normalize(itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer im2, mitk::Image::Pointer mask1, std::string output)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.