41 vtkInformationVector** inputVector,
42 vtkInformationVector* outputVector)
44 vtkDebugMacro(<<
"Executing VtkImageDataToPolyDataFilter");
46 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
47 vtkInformation* outInfo = outputVector->GetInformationObject(0);
49 vtkImageData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
51 vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
53 void* inScalarPtr = input->GetScalarPointer();
54 int numScalarComponents = input->GetNumberOfScalarComponents();
57 input->GetSpacing(spacing);
61 input->GetDimensions(dimensions);
64 vtkIdType numPts = input->GetNumberOfPoints();
67 vtkDebugMacro(
"No data to extract lines!");
72 output->Allocate(numPts);
75 vtkSmartPointer<vtkPoints> newPts = vtkSmartPointer<vtkPoints>::New();
76 newPts->SetNumberOfPoints(numPts * 2);
79 vtkPointData* inPD = input->GetPointData();
80 vtkPointData* outPD = output->GetPointData();
81 outPD->CopyAllocate(inPD, numPts * 16, numPts);
85 inPD->GetArray(0)->GetRange(range);
86 double const scalingFactor =
87 (std::max(dimensions[0], dimensions[1]) * spacing[0] * 0.1) /
88 std::max(range[0], range[1]);
90 double dir[3] = {0, 0, 1};
94 for (vtkIdType ptId = 0; ptId < numPts; ++ptId)
98 (
static_cast<float*
>(inScalarPtr))[ptId * numScalarComponents + 1];
99 if (opacity < 0.00000001f)
105 double const length =
106 (
static_cast<float*
>(inScalarPtr))[ptId * numScalarComponents] *
107 scalingFactor * this->LengthScaleFactor;
110 if (length < 0.00000001f)
117 input->GetPoint(ptId, p);
121 for (std::size_t i = 0; i < 3; ++i)
123 newPt[i] = p[i] + dir[i] * length;
127 newPts->SetPoint(ptId * 2, p);
128 outPD->CopyData(inPD, ptId, ptId * 2);
131 newPts->SetPoint(ptId * 2 + 1, newPt);
132 outPD->CopyData(inPD, ptId, ptId * 2 + 1);
135 vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
136 line->GetPointIds()->SetId(0, ptId * 2);
137 line->GetPointIds()->SetId(1, ptId * 2 + 1);
138 output->InsertNextCell(line->GetCellType(), line->GetPointIds());
142 output->SetPoints(newPts);
143 output->GetPointData()->GetArray(0)->SetName(
"Colors");
148 vtkDebugMacro(<<
"Created: " << newPts->GetNumberOfPoints() <<
" points, "
149 << output->GetNumberOfCells() <<
" lines");