vtk中獲取單點像素值

ROIData ROITool::computeVoxelValues(const QList<Line3D> &polygonSegments, Point3D sweepLineBeginPoint, Point3D sweepLineEndPoint, double sweepLineEnd, int inputNumber)
{
    // We get the pixel data to obtain voxels values from
    auto pixelData = m_2DViewer->getCurrentPixelDataFromInput(inputNumber);
    
    OrthogonalPlane currentView = pixelData.getOrthogonalPlane();
    int yIndex = currentView.getYIndex();

    double verticalSpacingIncrement = pixelData.getSpacing().y; // slice oriented

    // ROI voxel data to be obtained from the sweep line
    ROIData roiData;
    while (sweepLineBeginPoint.at(yIndex) <= sweepLineEnd)
    {
        // We get the intersections bewteen ROI segments and current sweep line
        QList<double*> intersectionList = getIntersectionPoints(polygonSegments, Line3D(sweepLineBeginPoint, sweepLineEndPoint), currentView);

        // Adding the voxels from the current intersections of the current sweep line to the voxel values list
        addVoxelsFromIntersections(intersectionList, currentView, pixelData, roiData);
        
        // Shift the sweep line the corresponding space in vertical direction
        sweepLineBeginPoint[yIndex] += verticalSpacingIncrement;
        sweepLineEndPoint[yIndex] += verticalSpacingIncrement;
    }

    return roiData;
}
void ROITool::addVoxelsFromIntersections(const QList<double*> &intersectionPoints, const OrthogonalPlane &view, SliceOrientedVolumePixelData &pixelData, ROIData &roiData)
{
    if (MathTools::isEven(intersectionPoints.count()))
    {
        int scanDirectionIndex = view.getXIndex();
        double scanDirectionIncrement = pixelData.getSpacing().x;   // slice oriented

        int limit = intersectionPoints.count() / 2;
        for (int i = 0; i < limit; ++i)
        {
            double *firstIntersection = intersectionPoints.at(i * 2);
            double *secondIntersection = intersectionPoints.at(i * 2 + 1);
            // First we check which will be the direction of the scan line
            Point3D currentScanLinePoint;
            double scanLineEnd;
            if (firstIntersection[scanDirectionIndex] <= secondIntersection[scanDirectionIndex])
            {
                for (int i = 0; i < 3; ++i)
                {
                    currentScanLinePoint[i] = firstIntersection[i];
                }
                scanLineEnd = secondIntersection[scanDirectionIndex];
            }
            else
            {
                for (int i = 0; i < 3; ++i)
                {
                    currentScanLinePoint[i] = secondIntersection[i];
                }
                scanLineEnd = firstIntersection[scanDirectionIndex];
            }
            // Then we scan and get the voxels along the line
            while (currentScanLinePoint.at(scanDirectionIndex) <= scanLineEnd)
            {
                // currentScanLinePoint is pixel data oriented
                double pixelDataOrientedPoint[4] = { currentScanLinePoint[0], currentScanLinePoint[1], currentScanLinePoint[2], 1.0 };
                double worldPoint[4];
                pixelData.getDataToWorldMatrix()->MultiplyPoint(pixelDataOrientedPoint, worldPoint);
                Vector3 voxelCoordinate(worldPoint);
                roiData.addVoxel(pixelData.getVoxelValue(voxelCoordinate));
                currentScanLinePoint[scanDirectionIndex] += scanDirectionIncrement;
            }
        }
    }
    else
    {
        DEBUG_LOG(QString("EL NOMBRE D'INTERSECCIONS ENTRE EL RAIG I LA ROI ÉS IMPARELL!!: %1").arg(intersectionPoints.count()));
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章