| 153 | } |
| 154 | |
| 155 | void mitk::SplineVtkMapper3D::UpdateSpline() |
| 156 | { |
| 157 | auto input = this->GetInput(); |
| 158 | // input->Update();//already done in superclass |
| 159 | |
| 160 | // Number of points on the spline |
| 161 | unsigned int numberOfOutputPoints = m_SplineResolution; |
| 162 | unsigned int numberOfInputPoints = input->GetSize(); |
| 163 | |
| 164 | if (numberOfInputPoints >= 2) |
| 165 | { |
| 166 | m_SplinesAvailable = true; |
| 167 | vtkCardinalSpline *splineX = vtkCardinalSpline::New(); |
| 168 | vtkCardinalSpline *splineY = vtkCardinalSpline::New(); |
| 169 | vtkCardinalSpline *splineZ = vtkCardinalSpline::New(); |
| 170 | unsigned int index = 0; |
| 171 | mitk::PointSet::DataType::PointsContainer::Pointer pointsContainer = input->GetPointSet()->GetPoints(); |
| 172 | for (mitk::PointSet::DataType::PointsContainer::Iterator it = pointsContainer->Begin(); |
| 173 | it != pointsContainer->End(); |
| 174 | ++it, ++index) |
| 175 | // for ( unsigned int i = 0 ; i < numberOfInputPoints; ++i ) |
| 176 | { |
| 177 | mitk::PointSet::PointType point = it->Value(); |
| 178 | splineX->AddPoint(index, point[0]); |
| 179 | splineY->AddPoint(index, point[1]); |
| 180 | splineZ->AddPoint(index, point[2]); |
| 181 | } |
| 182 | vtkPoints *points = vtkPoints::New(); |
| 183 | vtkPolyData *profileData = vtkPolyData::New(); |
| 184 | |
| 185 | // Interpolate x, y and z by using the three spline filters and |
| 186 | // create new points |
| 187 | double t = 0.0f; |
| 188 | for (unsigned int i = 0; i < numberOfOutputPoints; ++i) |
| 189 | { |
| 190 | t = ((((double)numberOfInputPoints) - 1.0f) / (((double)numberOfOutputPoints) - 1.0f)) * ((double)i); |
| 191 | points->InsertPoint(i, splineX->Evaluate(t), splineY->Evaluate(t), splineZ->Evaluate(t)); |
| 192 | } |
| 193 | |
| 194 | // Create the polyline. |
| 195 | vtkCellArray *lines = vtkCellArray::New(); |
| 196 | lines->InsertNextCell(numberOfOutputPoints); |
| 197 | for (unsigned int i = 0; i < numberOfOutputPoints; ++i) |
| 198 | lines->InsertCellPoint(i); |
| 199 | |
| 200 | profileData->SetPoints(points); |
| 201 | profileData->SetLines(lines); |
| 202 | |
| 203 | // Add thickness to the resulting line. |
| 204 | // vtkTubeFilter* profileTubes = vtkTubeFilter::New(); |
| 205 | // profileTubes->SetNumberOfSides(8); |
| 206 | // profileTubes->SetInput(profileData); |
| 207 | // profileTubes->SetRadius(.005); |
| 208 | |
| 209 | vtkPolyDataMapper *profileMapper = vtkPolyDataMapper::New(); |
| 210 | profileMapper->SetInputData(profileData); |
| 211 | |
| 212 | m_SplinesActor->SetMapper(profileMapper); |
no test coverage detected