90 mitk::Surface::Pointer output = this->GetOutput();
92 mitk::Image::Pointer input = this->GetInput();
95 int xDimension = input->GetDimension(0);
96 int yDimension = input->GetDimension(1);
97 unsigned int size = xDimension*yDimension;
98 std::vector<bool> isPointValid;
99 isPointValid.resize(size);
101 points->SetDataTypeToDouble();
106 textureCoords->SetNumberOfComponents(2);
107 textureCoords->Allocate(size);
114 m_VertexIdList->Allocate(size);
115 m_VertexIdList->SetNumberOfIds(size);
116 for(
unsigned int i = 0; i < size; ++i)
118 m_VertexIdList->SetId(i, 0);
121 float* scalarFloatData =
nullptr;
123 if (this->m_IplScalarImage)
125 scalarFloatData = (
float*)this->m_IplScalarImage->imageData;
127 else if (this->GetInput(m_TextureIndex))
129 ImageReadAccessor inputAcc(this->GetInput(m_TextureIndex));
130 scalarFloatData = (
float*)inputAcc.GetData();
133 ImageReadAccessor inputAcc(input, input->GetSliceData(0,0,0));
134 float* inputFloatData = (
float*)inputAcc.GetData();
138 if((m_ReconstructionMode == WithOutInterPixelDistance) || (m_ReconstructionMode == Kinect))
140 focalLengthInPixelUnits[0] = m_CameraIntrinsics->GetFocalLengthX();
141 focalLengthInPixelUnits[1] = m_CameraIntrinsics->GetFocalLengthY();
142 focalLengthInMm = 0.0;
144 else if( m_ReconstructionMode == WithInterPixelDistance)
147 focalLengthInPixelUnits[0] = 0.0;
148 focalLengthInPixelUnits[1] = 0.0;
149 focalLengthInMm = (m_CameraIntrinsics->GetFocalLengthX()*m_InterPixelDistance[0]+m_CameraIntrinsics->GetFocalLengthY()*m_InterPixelDistance[1])/2.0;
153 focalLengthInPixelUnits[0] = 0.0;
154 focalLengthInPixelUnits[1] = 0.0;
155 focalLengthInMm = 0.0;
159 principalPoint[0] = m_CameraIntrinsics->GetPrincipalPointX();
160 principalPoint[1] = m_CameraIntrinsics->GetPrincipalPointY();
162 mitk::Point3D origin = input->GetGeometry()->GetOrigin();
163 mitk::Vector3D spacing = input->GetGeometry()->GetSpacing();
165 for (
int j=0; j<yDimension; j++)
167 for (
int i=0; i<xDimension; i++)
169 unsigned int pixelID = i+j*xDimension;
176 unsigned int completeIndexX = i*spacing[0]+origin[0];
177 unsigned int completeIndexY = j*spacing[1]+origin[1];
180 switch (m_ReconstructionMode)
182 case WithOutInterPixelDistance:
187 case WithInterPixelDistance:
199 MITK_ERROR <<
"Incorrect reconstruction mode!";
203 if (distance<=mitk::eps)
205 isPointValid[pixelID] =
false;
209 isPointValid[pixelID] =
true;
215 m_VertexIdList->SetId(pixelID, points->InsertNextPoint(cartesianCoordinates.GetDataPointer()));
217 if (m_GenerateTriangularMesh)
219 if((i >= 1) && (j >= 1))
233 vtkIdType xy = pixelID;
234 vtkIdType x_1y = pixelID-1;
235 vtkIdType xy_1 = pixelID-xDimension;
236 vtkIdType x_1y_1 = xy_1-1;
239 vtkIdType xyV = m_VertexIdList->GetId(xy);
240 vtkIdType x_1yV = m_VertexIdList->GetId(x_1y);
241 vtkIdType xy_1V = m_VertexIdList->GetId(xy_1);
242 vtkIdType x_1y_1V = m_VertexIdList->GetId(x_1y_1);
244 if (isPointValid[xy]&&isPointValid[x_1y]&&isPointValid[x_1y_1]&&isPointValid[xy_1])
246 double pointXY[3], pointX_1Y[3], pointXY_1[3], pointX_1Y_1[3];
248 points->GetPoint(xyV, pointXY);
249 points->GetPoint(x_1yV, pointX_1Y);
250 points->GetPoint(xy_1V, pointXY_1);
251 points->GetPoint(x_1y_1V, pointX_1Y_1);
253 if( (
mitk::Equal(m_TriangulationThreshold, 0.0)) || ((vtkMath::Distance2BetweenPoints(pointXY, pointX_1Y) <= m_TriangulationThreshold)
254 && (vtkMath::Distance2BetweenPoints(pointXY, pointXY_1) <= m_TriangulationThreshold)
255 && (vtkMath::Distance2BetweenPoints(pointX_1Y, pointX_1Y_1) <= m_TriangulationThreshold)
256 && (vtkMath::Distance2BetweenPoints(pointXY_1, pointX_1Y_1) <= m_TriangulationThreshold)))
258 polys->InsertNextCell(3);
259 polys->InsertCellPoint(x_1yV);
260 polys->InsertCellPoint(xyV);
261 polys->InsertCellPoint(x_1y_1V);
263 polys->InsertNextCell(3);
264 polys->InsertCellPoint(x_1y_1V);
265 polys->InsertCellPoint(xyV);
266 polys->InsertCellPoint(xy_1V);
271 vertices->InsertNextCell(1);
272 vertices->InsertCellPoint(xyV);
280 vertices->InsertNextCell(1);
281 vertices->InsertCellPoint(m_VertexIdList->GetId(pixelID));
286 scalarArray->InsertTuple1(m_VertexIdList->GetId(pixelID), scalarFloatData[pixelID]);
289 float xNorm = (((float)i)/xDimension);
290 float yNorm = ((float)j)/yDimension;
291 textureCoords->InsertTuple2(m_VertexIdList->GetId(pixelID), xNorm, yNorm);
297 mesh->SetPoints(points);
298 mesh->SetPolys(polys);
299 mesh->SetVerts(vertices);
301 if (scalarArray->GetNumberOfTuples()>0)
303 mesh->GetPointData()->SetScalars(scalarArray);
306 mesh->GetPointData()->SetTCoords(textureCoords);
307 output->SetVtkPolyData(mesh);