20 #include <vtkCellArray.h> 21 #include <vtkPoints.h> 22 #include <vtkPolyData.h> 23 #include <vtkPointData.h> 24 #include <vtkFloatArray.h> 25 #include <vtkSmartPointer.h> 26 #include <vtkIdList.h> 32 m_IplScalarImage(nullptr), m_CameraIntrinsics(), m_TextureImageWidth(0), m_TextureImageHeight(0), m_InterPixelDistance(), m_TextureIndex(0),
33 m_GenerateTriangularMesh(true), m_TriangulationThreshold(0.0)
39 m_CameraIntrinsics->SetDistorsionCoeffs(-0.486690014601f,0.553943634033f,0.00222016777843f,-0.00300851115026f);
66 if ((distanceImage ==
nullptr) && (idx == this->GetNumberOfInputs() - 1))
67 this->SetNumberOfIndexedInputs(this->GetNumberOfInputs() - 1);
69 this->ProcessObject::SetNthInput(idx, distanceImage);
81 if (this->GetNumberOfInputs() < 1)
83 mitkThrow() <<
"No input given for ToFDistanceImageToSurfaceFilter";
85 return static_cast< mitk::Image*
>(this->ProcessObject::GetInput(idx));
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);
100 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
101 points->SetDataTypeToDouble();
102 vtkSmartPointer<vtkCellArray> polys = vtkSmartPointer<vtkCellArray>::New();
103 vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
104 vtkSmartPointer<vtkFloatArray> scalarArray = vtkSmartPointer<vtkFloatArray>::New();
105 vtkSmartPointer<vtkFloatArray> textureCoords = vtkSmartPointer<vtkFloatArray>::New();
106 textureCoords->SetNumberOfComponents(2);
107 textureCoords->Allocate(size);
116 for(
unsigned int i = 0; i < size; ++i)
121 float* scalarFloatData =
nullptr;
130 scalarFloatData = (
float*)inputAcc.
GetData();
134 float* inputFloatData = (
float*)inputAcc.
GetData();
142 focalLengthInMm = 0.0;
147 focalLengthInPixelUnits[0] = 0.0;
148 focalLengthInPixelUnits[1] = 0.0;
153 focalLengthInPixelUnits[0] = 0.0;
154 focalLengthInPixelUnits[1] = 0.0;
155 focalLengthInMm = 0.0;
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];
199 MITK_ERROR <<
"Incorrect reconstruction mode!";
205 isPointValid[pixelID] =
false;
209 isPointValid[pixelID] =
true;
215 m_VertexIdList->SetId(pixelID, points->InsertNextPoint(cartesianCoordinates.GetDataPointer()));
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;
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);
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);
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);
296 vtkSmartPointer<vtkPolyData> mesh = vtkSmartPointer<vtkPolyData>::New();
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);
312 this->SetNumberOfIndexedOutputs(this->GetNumberOfInputs());
313 for (
unsigned int idx = 0; idx < this->GetNumberOfOutputs(); ++idx)
316 DataObjectPointer newOutput = this->
MakeOutput(idx);
317 this->SetNthOutput(idx, newOutput);
325 itkDebugMacro(<<
"GenerateOutputInformation()");
int m_TextureIndex
Index of the input used as texture image when no scalar image was set via SetIplScalarImage(). 0 = Distance, 1 = Amplitude, 2 = Intensity.
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.
int m_TextureImageHeight
Height (y-dimension) of the texture image.
ToFProcessingCommon::ToFPoint2D m_InterPixelDistance
distance in mm between two adjacent pixels on the ToF camera chip
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.
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.
int m_TextureImageWidth
Width (x-dimension) of the texture image.
Image * GetInput()
Returns the input of this filter.
itk::Point< ToFScalarType, 2 > ToFPoint2D
double m_TriangulationThreshold
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...
bool m_GenerateTriangularMesh
itk::Point< ToFScalarType, 3 > ToFPoint3D
IplImage * m_IplScalarImage
Scalar image used for surface texturing.
~ToFDistanceImageToSurfaceFilter() override
Standard destructor.
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.
itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
void SetTriangulationThreshold(double triangulationThreshold)
SetTriangulationThreshold Sets a triangulation threshold in order to remove unusually huge faces from...
vtkSmartPointer< vtkIdList > m_VertexIdList
Make a vtkIdList to save the ID's of the polyData corresponding to the image pixel ID's...
MITKCORE_EXPORT const ScalarType eps
virtual void SetCameraIntrinsics(mitk::CameraIntrinsics::Pointer _arg)
ImageReadAccessor class to get locked read access for a particular image part.
IplImage * GetScalarImage()
Set scalar image used as texture of the surface.
const void * GetData() const
Gives const access to the data.
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.