24 #include <vtkCellArray.h>
25 #include <vtkPoints.h>
26 #include <vtkPolyData.h>
27 #include <vtkPointData.h>
28 #include <vtkFloatArray.h>
29 #include <vtkSmartPointer.h>
30 #include <vtkIdList.h>
36 m_IplScalarImage(nullptr), m_CameraIntrinsics(), m_TextureImageWidth(0), m_TextureImageHeight(0), m_InterPixelDistance(), m_TextureIndex(0),
37 m_GenerateTriangularMesh(true), m_TriangulationThreshold(0.0)
43 m_CameraIntrinsics->SetDistorsionCoeffs(-0.486690014601f,0.553943634033f,0.00222016777843f,-0.00300851115026f);
53 this->SetCameraIntrinsics(cameraIntrinsics);
54 this->SetInput(0,distanceImage);
59 this->SetCameraIntrinsics(cameraIntrinsics);
60 this->SetInput(idx,distanceImage);
65 this->SetInput(0,distanceImage);
70 if ((distanceImage ==
nullptr) && (idx == this->GetNumberOfInputs() - 1))
71 this->SetNumberOfInputs(this->GetNumberOfInputs() - 1);
73 this->ProcessObject::SetNthInput(idx, distanceImage);
75 this->CreateOutputsForAllInputs();
80 return this->GetInput(0);
85 if (this->GetNumberOfInputs() < 1)
87 mitkThrow() <<
"No input given for ToFDistanceImageToSurfaceFilter";
89 return static_cast< mitk::Image*
>(this->ProcessObject::GetInput(idx));
99 int xDimension = input->GetDimension(0);
100 int yDimension = input->GetDimension(1);
101 unsigned int size = xDimension*yDimension;
102 std::vector<bool> isPointValid;
103 isPointValid.resize(size);
105 points->SetDataTypeToDouble();
110 textureCoords->SetNumberOfComponents(2);
111 textureCoords->Allocate(size);
118 m_VertexIdList->Allocate(size);
119 m_VertexIdList->SetNumberOfIds(size);
120 for(
unsigned int i = 0; i < size; ++i)
122 m_VertexIdList->SetId(i, 0);
125 float* scalarFloatData =
nullptr;
127 if (this->m_IplScalarImage)
129 scalarFloatData = (
float*)this->m_IplScalarImage->imageData;
131 else if (this->GetInput(m_TextureIndex))
134 scalarFloatData = (
float*)inputAcc.
GetData();
138 float* inputFloatData = (
float*)inputAcc.
GetData();
142 if((m_ReconstructionMode == WithOutInterPixelDistance) || (m_ReconstructionMode == Kinect))
144 focalLengthInPixelUnits[0] = m_CameraIntrinsics->GetFocalLengthX();
145 focalLengthInPixelUnits[1] = m_CameraIntrinsics->GetFocalLengthY();
147 else if( m_ReconstructionMode == WithInterPixelDistance)
150 focalLengthInMm = (m_CameraIntrinsics->GetFocalLengthX()*m_InterPixelDistance[0]+m_CameraIntrinsics->GetFocalLengthY()*m_InterPixelDistance[1])/2.0;
154 principalPoint[0] = m_CameraIntrinsics->GetPrincipalPointX();
155 principalPoint[1] = m_CameraIntrinsics->GetPrincipalPointY();
160 for (
int j=0; j<yDimension; j++)
162 for (
int i=0; i<xDimension; i++)
164 unsigned int pixelID = i+j*xDimension;
171 unsigned int completeIndexX = i*spacing[0]+origin[0];
172 unsigned int completeIndexY = j*spacing[1]+origin[1];
175 switch (m_ReconstructionMode)
177 case WithOutInterPixelDistance:
182 case WithInterPixelDistance:
194 MITK_ERROR <<
"Incorrect reconstruction mode!";
200 isPointValid[pixelID] =
false;
204 isPointValid[pixelID] =
true;
210 m_VertexIdList->SetId(pixelID, points->InsertNextPoint(cartesianCoordinates.GetDataPointer()));
212 if (m_GenerateTriangularMesh)
214 if((i >= 1) && (j >= 1))
228 vtkIdType xy = pixelID;
229 vtkIdType x_1y = pixelID-1;
230 vtkIdType xy_1 = pixelID-xDimension;
231 vtkIdType x_1y_1 = xy_1-1;
234 vtkIdType xyV = m_VertexIdList->GetId(xy);
235 vtkIdType x_1yV = m_VertexIdList->GetId(x_1y);
236 vtkIdType xy_1V = m_VertexIdList->GetId(xy_1);
237 vtkIdType x_1y_1V = m_VertexIdList->GetId(x_1y_1);
239 if (isPointValid[xy]&&isPointValid[x_1y]&&isPointValid[x_1y_1]&&isPointValid[xy_1])
241 double pointXY[3], pointX_1Y[3], pointXY_1[3], pointX_1Y_1[3];
243 points->GetPoint(xyV, pointXY);
244 points->GetPoint(x_1yV, pointX_1Y);
245 points->GetPoint(xy_1V, pointXY_1);
246 points->GetPoint(x_1y_1V, pointX_1Y_1);
248 if( (
mitk::Equal(m_TriangulationThreshold, 0.0)) || ((vtkMath::Distance2BetweenPoints(pointXY, pointX_1Y) <= m_TriangulationThreshold)
249 && (vtkMath::Distance2BetweenPoints(pointXY, pointXY_1) <= m_TriangulationThreshold)
250 && (vtkMath::Distance2BetweenPoints(pointX_1Y, pointX_1Y_1) <= m_TriangulationThreshold)
251 && (vtkMath::Distance2BetweenPoints(pointXY_1, pointX_1Y_1) <= m_TriangulationThreshold)))
253 polys->InsertNextCell(3);
254 polys->InsertCellPoint(x_1yV);
255 polys->InsertCellPoint(xyV);
256 polys->InsertCellPoint(x_1y_1V);
258 polys->InsertNextCell(3);
259 polys->InsertCellPoint(x_1y_1V);
260 polys->InsertCellPoint(xyV);
261 polys->InsertCellPoint(xy_1V);
266 vertices->InsertNextCell(1);
267 vertices->InsertCellPoint(xyV);
275 vertices->InsertNextCell(1);
276 vertices->InsertCellPoint(m_VertexIdList->GetId(pixelID));
281 scalarArray->InsertTuple1(m_VertexIdList->GetId(pixelID), scalarFloatData[pixelID]);
284 float xNorm = (((float)i)/xDimension);
285 float yNorm = ((float)j)/yDimension;
286 textureCoords->InsertTuple2(m_VertexIdList->GetId(pixelID), xNorm, yNorm);
292 mesh->SetPoints(points);
293 mesh->SetPolys(polys);
294 mesh->SetVerts(vertices);
296 if (scalarArray->GetNumberOfTuples()>0)
298 mesh->GetPointData()->SetScalars(scalarArray);
301 mesh->GetPointData()->SetTCoords(textureCoords);
302 output->SetVtkPolyData(mesh);
307 this->SetNumberOfOutputs(this->GetNumberOfInputs());
308 for (
unsigned int idx = 0; idx < this->GetNumberOfOutputs(); ++idx)
309 if (this->GetOutput(idx) ==
nullptr)
311 DataObjectPointer newOutput = this->MakeOutput(idx);
312 this->SetNthOutput(idx, newOutput);
320 itkDebugMacro(<<
"GenerateOutputInformation()");
326 this->m_IplScalarImage = iplScalarImage;
332 return this->m_IplScalarImage;
337 this->m_TextureImageWidth = width;
342 this->m_TextureImageHeight = height;
350 this->m_TriangulationThreshold = triangulationThreshold*triangulationThreshold;
itk::SmartPointer< Self > Pointer
void CreateOutputsForAllInputs()
Create an output for each input.
static ToFPoint3D IndexToCartesianCoordinatesWithInterpixdist(unsigned int i, unsigned int j, ToFScalarType distance, ToFScalarType focalLength, ToFScalarType interPixelDistanceX, ToFScalarType interPixelDistanceY, ToFScalarType principalPointX, ToFScalarType principalPointY)
Convert index based distances to cartesian coordinates.
~ToFDistanceImageToSurfaceFilter()
Standard destructor.
ToFProcessingCommon::ToFPoint2D m_InterPixelDistance
distance in mm between two adjacent pixels on the ToF camera chip
const void * GetData() const
Gives const access to the data.
virtual void GenerateData() override
Method generating the output of this filter. Called in the updated process of the pipeline...
void SetTextureImageHeight(int height)
Set height of the scalar image used for texturing the surface.
virtual void GenerateOutputInformation() override
void SetScalarImage(IplImage *iplScalarImage)
Set scalar image used as texture of the surface.
ToFDistanceImageToSurfaceFilter()
Standard constructor.
virtual void SetInput(Image *distanceImage)
Sets the input of this filter.
ReconstructionModeType m_ReconstructionMode
The ReconstructionModeType enum: Defines the reconstruction mode, if using no interpixeldistances and...
mitk::CameraIntrinsics::Pointer m_CameraIntrinsics
Specifies the intrinsic parameters.
void SetTextureImageWidth(int width)
Set width of the scalar image used for texturing the surface.
Image * GetInput()
Returns the input of this filter.
itk::Point< ToFScalarType, 2 > ToFPoint2D
Image class for storing images.
static ToFProcessingCommon::ToFPoint3D KinectIndexToCartesianCoordinates(unsigned int i, unsigned int j, ToFScalarType distance, ToFScalarType focalLengthX, ToFScalarType focalLengthY, ToFScalarType principalPointX, ToFScalarType principalPointY)
KinectIndexToCartesianCoordinates Convert a pixel (i,j) with value d to a 3D world point...
itk::Point< ToFScalarType, 3 > ToFPoint3D
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.
void SetTriangulationThreshold(double triangulationThreshold)
SetTriangulationThreshold Sets a triangulation threshold in order to remove unusually huge faces from...
MITKCORE_EXPORT const ScalarType eps
ImageReadAccessor class to get locked read access for a particular image part.
IplImage * GetScalarImage()
Set scalar image used as texture of the surface.
static ToFPoint3D IndexToCartesianCoordinates(unsigned int i, unsigned int j, ToFScalarType distance, ToFScalarType focalLengthX, ToFScalarType focalLengthY, ToFScalarType principalPointX, ToFScalarType principalPointY)
Convert index based distances to cartesian coordinates.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.