18 #include <vtkIdList.h>
19 #include <vtkImageData.h>
20 #include <vtkInformation.h>
21 #include <vtkInformationVector.h>
23 #include <vtkObjectFactory.h>
24 #include <vtkPointData.h>
25 #include <vtkPolyData.h>
26 #include <vtkSmartPointer.h>
32 this->SetLengthScaleFactor(1.0);
39 this->Superclass::PrintSelf(os, indent);
40 os << indent <<
"LengthScaleFactor: " << this->LengthScaleFactor <<
"\n";
44 int , vtkInformation* info)
46 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkImageData");
52 vtkInformationVector** inputVector,
53 vtkInformationVector* outputVector)
55 vtkDebugMacro(<<
"Executing VtkImageDataToPolyDataFilter");
57 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
58 vtkInformation* outInfo = outputVector->GetInformationObject(0);
60 vtkImageData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
62 vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
64 void* inScalarPtr = input->GetScalarPointer();
65 int numScalarComponents = input->GetNumberOfScalarComponents();
68 input->GetSpacing(spacing);
72 input->GetDimensions(dimensions);
75 vtkIdType numPts = input->GetNumberOfPoints();
78 vtkDebugMacro(
"No data to extract lines!");
83 output->Allocate(numPts);
86 vtkSmartPointer<vtkPoints> newPts = vtkSmartPointer<vtkPoints>::New();
87 newPts->SetNumberOfPoints(numPts * 2);
90 vtkPointData* inPD = input->GetPointData();
91 vtkPointData* outPD = output->GetPointData();
92 outPD->CopyAllocate(inPD, numPts * 16, numPts);
96 inPD->GetArray(0)->GetRange(range);
97 double const scalingFactor =
98 (std::max(dimensions[0], dimensions[1]) * spacing[0] * 0.1) /
99 std::max(range[0], range[1]);
101 double dir[3] = {0, 0, 1};
105 for (vtkIdType ptId = 0; ptId < numPts; ++ptId)
109 (
static_cast<float*
>(inScalarPtr))[ptId * numScalarComponents + 1];
110 if (opacity < 0.00000001f)
116 double const length =
117 (
static_cast<float*
>(inScalarPtr))[ptId * numScalarComponents] *
118 scalingFactor * this->LengthScaleFactor;
121 if (length < 0.00000001f)
128 input->GetPoint(ptId,
p);
132 for (std::size_t i = 0; i < 3; ++i)
134 newPt[i] =
p[i] + dir[i] * length;
138 newPts->SetPoint(ptId * 2,
p);
139 outPD->CopyData(inPD, ptId, ptId * 2);
142 newPts->SetPoint(ptId * 2 + 1, newPt);
143 outPD->CopyData(inPD, ptId, ptId * 2 + 1);
146 vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
147 line->GetPointIds()->SetId(0, ptId * 2);
148 line->GetPointIds()->SetId(1, ptId * 2 + 1);
149 output->InsertNextCell(line->GetCellType(), line->GetPointIds());
153 output->SetPoints(newPts);
154 output->GetPointData()->GetArray(0)->SetName(
"Colors");
159 vtkDebugMacro(<<
"Created: " << newPts->GetNumberOfPoints() <<
" points, "
160 << output->GetNumberOfCells() <<
" lines");
vtkStandardNewMacro(VtkImageDataToLinePolyDataFilter)
Definition of the VtkImageDataToLinePolyDataFilter class.
Creates lines that stand on top of the image with the length of the corresponding first sub-pixel val...
VtkImageDataToLinePolyDataFilter()
Constructor.
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Converts the image data to lines.
double ImageSpacing
The spacing of the image.
void PrintSelf(ostream &os, vtkIndent indent) override
Prints information about itself.
int FillInputPortInformation(int port, vtkInformation *info) override
Sets input port to vtkImageData.
~VtkImageDataToLinePolyDataFilter() override
Destructor.