Converts the image data to lines.
54{
55 vtkDebugMacro(<< "Executing VtkImageDataToPolyDataFilter");
56
57 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
58 vtkInformation* outInfo = outputVector->GetInformationObject(0);
59 vtkImageData* input =
60 vtkImageData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
61 vtkPolyData* output =
62 vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
63
64 void* inScalarPtr = input->GetScalarPointer();
65 int numScalarComponents = input->GetNumberOfScalarComponents();
66
67 double spacing[3];
68 input->GetSpacing(spacing);
70
71 int dimensions[3];
72 input->GetDimensions(dimensions);
73
74
75 vtkIdType numPts = input->GetNumberOfPoints();
76 if (numPts < 1)
77 {
78 vtkDebugMacro("No data to extract lines!");
79 return 1;
80 }
81
82
83 output->Allocate(numPts);
84
85
86 vtkSmartPointer<vtkPoints> newPts = vtkSmartPointer<vtkPoints>::New();
87 newPts->SetNumberOfPoints(numPts * 2);
88
89
90 vtkPointData* inPD = input->GetPointData();
91 vtkPointData* outPD = output->GetPointData();
92 outPD->CopyAllocate(inPD, numPts * 16, numPts);
93
94
95 double range[2];
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]);
100
101 double dir[3] = {0, 0, 1};
102
103
104
105 for (vtkIdType ptId = 0; ptId < numPts; ++ptId)
106 {
107
108 float opacity =
109 (static_cast<float*>(inScalarPtr))[ptId * numScalarComponents + 1];
110 if (opacity < 0.00000001f)
111 {
112 continue;
113 }
114
115
116 double const length =
117 (static_cast<float*>(inScalarPtr))[ptId * numScalarComponents] *
118 scalingFactor * this->LengthScaleFactor;
119
120
121 if (length < 0.00000001f)
122 {
123 continue;
124 }
125
126
128 input->GetPoint(ptId, p);
129
130
131 double newPt[3];
132 for (std::size_t i = 0; i < 3; ++i)
133 {
134 newPt[i] =
p[i] + dir[i] * length;
135 }
136
137
138 newPts->SetPoint(ptId * 2, p);
139 outPD->CopyData(inPD, ptId, ptId * 2);
140
141
142 newPts->SetPoint(ptId * 2 + 1, newPt);
143 outPD->CopyData(inPD, ptId, ptId * 2 + 1);
144
145
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());
150 }
151
152
153 output->SetPoints(newPts);
154 output->GetPointData()->GetArray(0)->SetName("Colors");
155
156
157 output->Squeeze();
158
159 vtkDebugMacro(<< "Created: " << newPts->GetNumberOfPoints() << " points, "
160 << output->GetNumberOfCells() << " lines");
161
162 return 1;
163}
double ImageSpacing
The spacing of the image.