Beispiel #1
0
void MainWindow::setUpForOctRaw(vtkSmartPointer<vtkPolyData> polyData, std::vector<uint8_t> &octdata, int frameHeader, int fileHeader)
{
    //If length, width or depth are less than 1, break out
    assert(m_rawLength > 0 && m_rawWidth > 0 && m_rawDepth > 0);

    uint32_t totalPoints = m_rawLength * m_rawWidth * m_rawDepth;

    //If the total number of points is higher than the threshold MAXPOINTS,
    //then determine the preMaskRatio to get it to around MAXPOINTS points
    m_preMaskRatio = 1;
    if(totalPoints > MAXPOINTS)
    {
        m_preMaskRatio = (uint32_t)(totalPoints/MAXPOINTS + 0.5);
    }

    //Setup some of the data in the UI
    this->ui->LengthPointsBox->setText(QString::number(m_rawLength));
    this->ui->WidthPointsBox->setText(QString::number(m_rawWidth));
    this->ui->DepthPointsBox->setText(QString::number(m_rawDepth));
    this->ui->TotalPointsBox->setText(QString::number(totalPoints));

    //Creates an array for point coordinates, and one for the scalars
    VTK_NEW(vtkPoints, points);
    VTK_NEW(vtkTypeUInt8Array, dataArray);

    //This is used to skip vertices according to preMaskRatio
    int skip = 0;

    //Update status bar
    this->statusBar()->showMessage("Building point data... ");
    QApplication::processEvents();

    for(int i = 0; i < m_rawLength; i++)
    {
        for(int j = 0; j < m_rawWidth; j++)
        {
            for(int k = 0; k < m_rawDepth; k++)
            {
                skip++;
                //Adds a vertex only when skip == preMaskRatio
                if(skip == m_preMaskRatio)
                {
                    int val = octdata[i*m_rawWidth*m_rawDepth + j*m_rawDepth + k + frameHeader*i + fileHeader];
                    points->InsertNextPoint(i, j, k);// + val*0.1 + 0.02*(rand()%100));
                    dataArray->InsertNextValue(val);
                    skip = 0;
                }
            }
        }
    }    

    //Create a polyData and loads verts and scalars into it
    polyData->SetPoints(points);
    polyData->GetPointData()->SetScalars(dataArray);

    //Update status bar
    this->statusBar()->showMessage("Building point data... done!");
    QApplication::processEvents();

    //This outputs all point data and coordinates. Use for debugging!
//    for(int i = 0; i < width*length*depth; i++)
//    {
//        double coords[3];
//        double* scalar = new double;
//        polyData->GetPoint(i, coords);
//        scalar = polyData->GetPointData()->GetScalars()->GetTuple(i);
//        std::cout << "Point " << i << ", at " << coords[0] << ", "
//              << coords[1] << ", " << coords[2] << ", has scalar "
//              << scalar[0] << "\n";
//    }

    //Update the axes to an adequate size
    m_axesActor->SetTotalLength(m_rawLength/3, m_rawWidth/3, (m_rawLength + m_rawWidth)/6);

    //Extract the scalar ranges from polydata for display at the UI
    double range[2];
    m_rawOctPolyData->GetScalarRange(range);
    this->ui->RawMinBox->setText(QString::number(range[0]));
    this->ui->RawMaxBox->setText(QString::number(range[1]));

    //Create vertices out of each point in polydata
    m_vertexFilter->SetInputConnection(m_maskFilter->GetOutputPort());

    //Scale the group of vertices
    m_trans->Scale(1.0, 1.0, 1.0);//((m_rawLength+m_rawWidth)/2.0)/m_rawDepth);
    m_transFilter->SetInputConnection(m_vertexFilter->GetOutputPort());
    m_transFilter->SetTransform(m_trans);

    //Generate an outline around the entire volume, to be displayed with the
    //single slice, for some context around the data
    m_outlineFilter->SetInputConnection(m_transFilter->GetOutputPort());

    //Optional filter for visualizing slices of the polydata
    m_box->SetBounds(0, 0.5, 0, m_rawWidth, 0, m_rawDepth);
    m_clipFilter->SetInputConnection(m_transFilter->GetOutputPort());
    m_clipFilter->SetClipFunction(m_box);
    m_clipFilter->InsideOutOn();

    //Create an outline around the slice as well
    m_sliceOutlineFilter->SetInputConnection(m_clipFilter->GetOutputPort());

    //Append the two outlines together
    m_appendFilter->AddInputConnection(m_outlineFilter->GetOutputPort());
    m_appendFilter->AddInputConnection(m_sliceOutlineFilter->GetOutputPort());

    //Create an actor out of the two outlines
    m_outlineMapper->SetInputConnection(m_appendFilter->GetOutputPort());
    m_outlineActor->SetMapper(m_outlineMapper);

    //Lookup table to represent alpha values based on the scalar values
    m_lut->SetRange(m_rawOctPolyData->GetPointData()->GetScalars()->GetRange());
    m_lut->SetValueRange(0.0, 1.0);
    m_lut->SetAlphaRange(0.0, 1.0);
    m_lut->SetSaturationRange(0.0, 0.0);
    m_lut->SetRampToSCurve();
    m_lut->Build();

    //Wire the transFilter output to the mapper
    m_mapper->SetInputConnection(m_transFilter->GetOutputPort());

}
Beispiel #2
0
void MainWindow::renderOctSurface()
{
    //Currently, vtkDelaunay2D (below) produces better results than
    //anything out of vtkSurfaceReconstructionFilter. This probably
    //won't be the case once I try with real oct images: Since delaunay2D
    //Tries to connect every single point, a single noise point would
    //greatly deform the mesh
    //===============================================
//    //Reconstructs a surface out of unorganized points
//    VTK_NEW(vtkSurfaceReconstructionFilter, surfaceFilter);
//    surfaceFilter->SetInputData(m_surfacePolyData);

//    //Required to "complete" using vtkSurfaceReconstructionFilter
//    VTK_NEW(vtkContourFilter, contourFilter);
//    contourFilter->SetInputConnection(surfaceFilter->GetOutputPort());
//    contourFilter->SetValue(0, 0.0);

//    //Sometimes the contouring algorithm can create a volume whose gradient
//    //vector and ordering of polygon (right hand rule) are inconsistent.
//    //This fixes this problem
//    VTK_NEW(vtkReverseSense, reverseFilter);
//    reverseFilter->SetInputConnection(contourFilter->GetOutputPort());
//    reverseFilter->ReverseCellsOn();
//    reverseFilter->ReverseNormalsOn();
    //================================================

    //Projects all points to a 2d X,Y plane and procedurally connects them to
    //each other to produce a surface out of triangles
    VTK_NEW(vtkDelaunay2D, delFilter);
    delFilter->SetInputData(m_surfacePolyData);
    delFilter->SetTolerance(0.001);
    //delFilter->Update();

    //Reduces the number of triangles in a mesh
//    VTK_NEW(vtkDecimatePro, decimateFilter);
//    decimateFilter->SetInputConnection(delFilter->GetOutputPort());
//    decimateFilter->SetTargetReduction(0.9);
//    decimateFilter->SetPreserveTopology(1);

    //Shifts the point positions to produce a smoother surface
    VTK_NEW(vtkSmoothPolyDataFilter, smoothFilter);
    smoothFilter->SetInputConnection(delFilter->GetOutputPort());
    smoothFilter->SetNumberOfIterations(100);

    //Produces smoother normals for the surface
    VTK_NEW(vtkPolyDataNormals, normalsFilter);
    normalsFilter->SetInputConnection(smoothFilter->GetOutputPort());
    normalsFilter->ComputeCellNormalsOn();
    normalsFilter->SetFeatureAngle(80);

//    VTK_NEW(vtkContourFilter, contourFilter);
//    contourFilter->SetInputConnection(delFilter->GetOutputPort());
//    contourFilter->GenerateValues(20, 0, 255);

    VTK_NEW(vtkPolyDataMapper, surfaceMapper);
    surfaceMapper->SetInputConnection(normalsFilter->GetOutputPort());
    surfaceMapper->ScalarVisibilityOn();
    surfaceMapper->InterpolateScalarsBeforeMappingOff();
    surfaceMapper->SetColorMode(VTK_COLOR_MODE_MAP_SCALARS);
    surfaceMapper->SetLookupTable(m_lut);
    surfaceMapper->UseLookupTableScalarRangeOn();

    m_octSurfaceActor->SetMapper(m_mapper);

    m_renderer->RemoveActor(m_octRawActor);
    m_renderer->AddActor(m_octSurfaceActor);

    this->ui->qvtkWidget->update();
}
Beispiel #3
0
void SolutionDialog::on_pushButton_3_clicked()
{

    if(ui->cob_x->currentIndex()==-1&&ui->cob_y->currentIndex()==-1&&ui->cob_z->currentIndex()==-1)
    {
        return;
    }
    qDebug()<<ui->cob_x->currentText()<<ui->cob_y->currentText();
        int dim = CoreDB->bases[baseindex].celldim;
         int coorddim = 0;
        if(CoreDB->bases[baseindex].zones[zoneindex].type == 2){
            coorddim = CoreDB->bases[baseindex].zones[zoneindex].dim[0]*CoreDB->bases[baseindex].zones[zoneindex].dim[1]*CoreDB->bases[baseindex].zones[zoneindex].dim[2];
        }else
        {
            coorddim = CoreDB->bases[baseindex].zones[zoneindex].dim[0];
        }
        vtkSmartPointer<vtkPoints> points =
                vtkSmartPointer<vtkPoints>::New();
        vtkSmartPointer<vtkDoubleArray> pointDataArray =
            vtkSmartPointer<vtkDoubleArray>::New();
          pointDataArray->Initialize();

        if(dim==2){
            sol_x = ui->cob_x->currentIndex();
            sol_y = ui->cob_y->currentIndex();
            int count = 0;
            if(sol_x != -1)
                count++;
            if(sol_y != -1)
                count++;
            if(count == 1){
               if(sol_x==-1){
                   sol_x = sol_y;
               }
            }
             pointDataArray->SetNumberOfComponents(count);
              for(int i=0;i<coorddim;i++)
              {
                  double x =CoreDB->bases[baseindex].zones[zoneindex].verts[i].x;
                  double y =CoreDB->bases[baseindex].zones[zoneindex].verts[i].y;
                  double xy[2];
                  xy[0] = x;
                  xy[1] = y;
                  points->InsertNextPoint(xy);
                  if(count == 1)
                  {
                     pointDataArray->InsertNextValue(CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_x].data[i]);
                  }else if(count == 2)
                  {
                     pointDataArray->InsertNextTuple2(CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_x].data[i],CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_y].data[i]);
                  }else{
                      return ;
                  }
              }
              //set salars



        }else if(dim==3)
        {
            sol_x = ui->cob_x->currentIndex();
            sol_y = ui->cob_y->currentIndex();
            sol_z = ui->cob_z->currentIndex();
            int count = 0;
            if(sol_x != -1)
                count++;
            if(sol_y != -1)
                count++;
            if(sol_z != -1)
                count++;

            pointDataArray->SetNumberOfComponents(count);
            for(int i=0;i<coorddim;i++)
            {
                double x =CoreDB->bases[baseindex].zones[zoneindex].verts[i].x;
                double y =CoreDB->bases[baseindex].zones[zoneindex].verts[i].y;
                double z =CoreDB->bases[baseindex].zones[zoneindex].verts[i].z;
                points->InsertNextPoint(x,y,z);

                if(count == 1)
                {
                   pointDataArray->InsertNextValue(CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_x].data[i]);
                }else if(count == 2)
                {
                   pointDataArray->InsertNextTuple2(CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_x].data[i],CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_y].data[i]);
                }else if(count == 3)
                {
                    pointDataArray->InsertNextTuple3(CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_x].data[i],CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_y].data[i],CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_z].data[i]);

                }else{
                    return ;
                }
            }

        }

       vtkSmartPointer<vtkPolyVertex> polyvertex = vtkSmartPointer<vtkPolyVertex>::New();
        polyvertex->GetPointIds()->SetNumberOfIds(coorddim);
        int i=0;
        for(i=0;i<coorddim;i++)
        {
           polyvertex->GetPointIds()->SetId(i,i);
        }
        vtkSmartPointer<vtkUnstructuredGrid> grid = vtkSmartPointer<vtkUnstructuredGrid>::New();

        grid->SetPoints(points);
//        grid->InsertNextCell(polyvertex->GetCellType(),
//                  polyvertex->GetPointIds());

       grid->GetPointData()->SetScalars(pointDataArray);

     if(dim==2){
         vtkSmartPointer<vtkDelaunay2D> delaunay
             = vtkSmartPointer<vtkDelaunay2D>::New();
          delaunay->SetTolerance(0.00001);
          delaunay->SetInputData(grid);

          delaunay->Update();
          double range[2];
          grid->GetScalarRange(range);
          qDebug()<<range[0]<<range[1];
          vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
          lut->SetRampToLinear();
          lut->SetNumberOfColors( 256 );
          lut->SetHueRange(0.667,0.0);
          lut->SetRange(range);
          lut->Build();
//          lut->SetNumberOfTableValues(6);
//          lut->SetRange(range);
//          lut->Build();
//          vtkSmartPointer<vtkNamedColors> namedColors =
//              vtkSmartPointer<vtkNamedColors>::New();
//       //
//       //  lut->SetHueRange(0.667,0.0);


////          lut->SetNumberOfColors(6);

//            double rgba[4];
//                    // Test setting and getting colors here.
//                   namedColors->GetColor("Red",rgba);
//                    namedColors->SetColor("My Red",rgba);
//                    namedColors->GetColor("My Red",rgba);
//                    lut->SetTableValue(0,rgba);
//                    namedColors->GetColor("DarkGreen",rgba);
//                   lut->SetTableValue(1,rgba);

//                   // Alternatively we can use tuple methods here:
//                  lut->SetTableValue(2,namedColors->GetColor4d("Blue").GetData());
//                   lut->SetTableValue(3,namedColors->GetColor4d("Cyan").GetData());
//                    lut->SetTableValue(4,namedColors->GetColor4d("Magenta").GetData());
//                   lut->SetTableValue(5,namedColors->GetColor4d("Yellow").GetData());
//                  //  lut->SetTableValue(6,namedColors->GetColor4d("White").GetData());





                   VTK_NEW(vtkSmoothPolyDataFilter, smoothFilter);
                      smoothFilter->SetInputConnection(delaunay->GetOutputPort());
                      smoothFilter->SetNumberOfIterations(100);

                      //Produces smoother normals for the surface
                      VTK_NEW(vtkPolyDataNormals, normalsFilter);
                      normalsFilter->SetInputConnection(smoothFilter->GetOutputPort());
                      normalsFilter->ComputeCellNormalsOn();
                      normalsFilter->SetFeatureAngle(80);




          vtkSmartPointer<vtkCleanPolyData> filledContours =
              vtkSmartPointer<vtkCleanPolyData>::New();
           filledContours->SetInputConnection(delaunay->GetOutputPort());

           vtkSmartPointer<vtkPolyDataMapper> contourMapper =
              vtkSmartPointer<vtkPolyDataMapper>::New();
          //  contourMapper->SetInputConnection(filledContours->GetOutputPort());
            contourMapper->SetInputConnection(normalsFilter->GetOutputPort());
            contourMapper->SetScalarRange(range[0], range[1]);


             contourMapper->Update();


            vtkSmartPointer<vtkActor> contourActor =
               vtkSmartPointer<vtkActor>::New();
             contourActor->SetMapper(contourMapper);
             contourActor->GetProperty()->SetInterpolationToFlat();


         vtkSmartPointer<vtkContourFilter> popSurface =
           vtkSmartPointer<vtkContourFilter>::New();
         popSurface->SetInputConnection(normalsFilter->GetOutputPort());

           popSurface->GenerateValues(5, .99*range[0], .99*range[1]);

           popSurface->ComputeScalarsOn();
           popSurface->ComputeGradientsOff();





           vtkSmartPointer<vtkPolyDataMapper> vectorMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
           vectorMapper->SetInputConnection(popSurface->GetOutputPort());

           vectorMapper->SetScalarRange(range);
            vectorMapper->SetLookupTable(lut);

           vectorMapper->SetScalarVisibility(1);
           vectorMapper->UseLookupTableScalarRangeOn();
           vectorMapper->SetColorModeToMapScalars();
           vectorMapper->Update();
           vtkSmartPointer<vtkActor> vectorActor = vtkSmartPointer<vtkActor>::New();
           vectorActor->SetMapper(vectorMapper);
           vectorActor->GetProperty()->SetInterpolationToFlat();



           VTK_NEW(vtkScalarBarActor, colorbar);
           colorbar->SetTitle("color");
           vtkSmartPointer<vtkTextProperty> prop = colorbar->GetLabelTextProperty ();
             prop->SetFontSize (8);
           colorbar->SetTitleTextProperty(prop);
                   colorbar->SetOrientationToVertical();
                   colorbar->SetPosition(0.8,0.1);
                   colorbar->SetPosition2(0.9,0.9);
                   colorbar->SetWidth(0.2);
                   colorbar->SetNumberOfLabels(6);
                   colorbar->SetLookupTable(lut);


           ren->RemoveAllViewProps();
           ren->AddViewProp(vectorActor);
          // ren->AddViewProp(contourActor);
           ren->AddActor2D(colorbar);
           //ren->AddViewProp(colorbar);
           ren->ResetCamera();
           vtkWidget->update();
           ui->verticalLayout->update();
     }else if(dim == 3)
     {
         vtkSmartPointer<vtkDelaunay3D> delaunay
             = vtkSmartPointer<vtkDelaunay3D>::New();

          delaunay->SetInputData(grid);

          delaunay->Update();


         vtkSmartPointer<vtkContourFilter> popSurface =
           vtkSmartPointer<vtkContourFilter>::New();
           popSurface->SetInputConnection(delaunay->GetOutputPort());
           double range[2];
           grid->GetScalarRange(range);

           vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();

           lut->SetRange(range);
           lut->SetNumberOfTableValues(6);
           lut->Build();
           popSurface->GenerateValues(5, range[0], range[1]);

           popSurface->ComputeScalarsOff();
           popSurface->ComputeGradientsOff();


           vtkSmartPointer<vtkPolyDataMapper> vectorMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
            vectorMapper->SetInputConnection(popSurface->GetOutputPort());
          //  vectorMapper->SetInputData(grid);
vectorMapper->SetScalarModeToUsePointFieldData();
vectorMapper->ColorByArrayComponent(0,0);
           vectorMapper->SetScalarRange(range);
           vectorMapper->SetLookupTable(lut);
           vectorMapper->SetScalarModeToUseCellData();
           vectorMapper->SetScalarVisibility(1);
           vtkSmartPointer<vtkActor> vectorActor = vtkSmartPointer<vtkActor>::New();
           vectorActor->SetMapper(vectorMapper);
           vectorActor->GetProperty()->SetInterpolationToFlat();
           ren->RemoveAllViewProps();
           ren->AddViewProp(vectorActor);
           ren->ResetCamera();
           vtkWidget->update();
           ui->verticalLayout->update();

     }



return ;

}
Beispiel #4
0
void MainWindow::renderOctMedianFilter()
{
    //Just jump out in case this is called before we have data
    if(m_rawOctPolyData->GetPointData()->GetNumberOfTuples() == 0) return;

    //We've already processed this median filter, just display it
    if(m_newMedFiltered == false &&
            m_rawOctPolyData->GetPointData()->GetNumberOfTuples() != 0)
    {
        //Re-wire the filters so we can interact with the raw points
        m_maskFilter->SetInputData(m_medFiltPolyData);

        //Setup the actor in the renderer
        m_renderer->RemoveAllViewProps();
        m_renderer->AddActor(m_octMedFiltActor);

        //Restore the axes actor if enabled
        if(this->ui->ShowAxesCheckbox->isChecked())
        {
            m_renderer->AddActor(m_axesActor);
        }

        //Restore the outline actor if in slice mode
        if(this->ui->ShowSliceCheckbox->isChecked())
        {
            m_renderer->AddActor(m_outlineActor);
        }

        //Update status bar
        this->statusBar()->showMessage("Displaying previously"
                                       " median-filtered OCT data... ");
        QApplication::processEvents();

        //Calculate and display the entire pipeline
        this->ui->qvtkWidget->update();

        //Update status bar
        this->statusBar()->showMessage("Displaying previously"
                                       " median-filtered OCT data... done!");
        QApplication::processEvents();

        return;
    }

    //Create a double vector instead of a char, so only one cast instead of 26
    std::vector<double> rol;

    //Get a pointer to the old scalars array to prevent repeated array access
    vtkTypeUInt8Array* scalars = vtkTypeUInt8Array::SafeDownCast(
                m_rawOctPolyData->GetPointData()->GetScalars());

    //This array will hold the median-filtered values
    VTK_NEW(vtkTypeUInt8Array, avgScalars);
    uint32_t numScalars = scalars->GetNumberOfTuples();
    avgScalars->SetNumberOfValues(numScalars);

    //Start at the first point that has all the 26 neighbors
    uint32_t index = m_rawDepth*m_rawWidth+m_rawDepth+1;

    //Update status bar
    this->statusBar()->showMessage("Applying median filter... clearing edges");
    QApplication::processEvents();

    for(int num = 0; num < numScalars; num++)
    {
        avgScalars->SetValue(num, 0);
    }

    QString indicator;

    for(int i = 1; i < m_rawLength-1; i++)
    {
        for(int j = 1; j < m_rawWidth-1; j++)
        {
            for(int k = 1; k < m_rawDepth-1; k++)
            {
                index = k + j*m_rawDepth + i*m_rawDepth*m_rawWidth;

                //Center point
                rol.push_back(  *(scalars->GetTuple(index))  );

                //Points in the same B-scan
                rol.push_back(  *(scalars->GetTuple(index+1))  );
                rol.push_back(  *(scalars->GetTuple(index-1))  );
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth))  );
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth+1))  );
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth-1))  );
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth))  );
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth+1))  );
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth-1))  );

                //Points in the next B-scan
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth*m_rawWidth))  );
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth*m_rawWidth+1))  );
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth*m_rawWidth-1))  );
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth*m_rawWidth+m_rawDepth))  );
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth*m_rawWidth+m_rawDepth+1))  );
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth*m_rawWidth+m_rawDepth-1))  );
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth*m_rawWidth-m_rawDepth))  );
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth*m_rawWidth-m_rawDepth+1))  );
                rol.push_back(  *(scalars->GetTuple(index+m_rawDepth*m_rawWidth-m_rawDepth-1))  );

                //Points in the previous B-scan
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth*m_rawWidth))  );
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth*m_rawWidth+1))  );
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth*m_rawWidth-1))  );
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth*m_rawWidth+m_rawDepth))  );
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth*m_rawWidth+m_rawDepth+1))  );
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth*m_rawWidth+m_rawDepth-1))  );
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth*m_rawWidth-m_rawDepth))  );
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth*m_rawWidth-m_rawDepth+1))  );
                rol.push_back(  *(scalars->GetTuple(index-m_rawDepth*m_rawWidth-m_rawDepth-1))  );

                //Sorts the values in the rol
                std::sort(rol.begin(), rol.end());

                //Inserts the filtered value in the new scalars array
                avgScalars->SetValue(index, rol[ rol.size()/2 ]);

                //Clears the vector for the next point
                rol.clear();
            }
        }
        //Update status bar
        this->statusBar()->showMessage(QString("Applying median filter... B-scan ") + indicator.number(i) + QString(" of ") + indicator.number(m_rawLength-1));
        //QApplication::processEvents();
    }

    //Sets the old points (same coordinates) and new, median-filtered scalars
    //into the new polyData
    m_medFiltPolyData->SetPoints(m_rawOctPolyData->GetPoints());
    m_medFiltPolyData->GetPointData()->SetScalars(avgScalars);

//    for(int i = 0; i < m_rawDepth*m_rawWidth*m_rawLength; i++)
//    {
//        double coords[3];
//        double* scalar = new double;
//        m_medFiltPolyData->GetPoint(i, coords);
//        scalar = m_medFiltPolyData->GetPointData()->GetScalars()->GetTuple(i);
//        std::cout << "Point " << i << ", at " << coords[0] << ", "
//                  << coords[1] << ", " << coords[2] << ", has scalar "
//                  << scalar[0] << "\n";
//    }


    //Setup the user-controlled mask filter
    m_maskFilter->SetInputData(m_medFiltPolyData);
    this->ui->VerticesToSkipSpinbox->setValue(m_maskRatio);
    this->on_VerticesToSkipSpinbox_editingFinished();

    //Configures the mapper
    m_mapper->SetColorMode(VTK_COLOR_MODE_MAP_SCALARS);
    m_mapper->SetLookupTable(m_lut);
    m_mapper->UseLookupTableScalarRangeOn();
    m_mapper->SetScalarVisibility(1);
    m_mapper->InterpolateScalarsBeforeMappingOff();

    //Sets the mapper into the actor
    m_octMedFiltActor->SetMapper(m_mapper);

    //Adds the median filter actor to the renderer
    m_renderer->RemoveAllViewProps();
    m_renderer->AddActor(m_octMedFiltActor);

    //Restore the axes actor if enabled
    if(this->ui->ShowAxesCheckbox->isChecked())
    {
        m_renderer->AddActor(m_axesActor);
    }

    //Restore the outline actor if in slice mode
    if(this->ui->ShowSliceCheckbox->isChecked())
    {
        m_renderer->AddActor(m_outlineActor);
    }

    //Sets the state
    m_newMedFiltered = false;
    m_newSurface = true;

    //Update status bar
    this->statusBar()->showMessage("Calculating median filter pipeline... ");
    QApplication::processEvents();

    //Updates the entire pipeline
    this->ui->qvtkWidget->update();

    //Update status bar
    this->statusBar()->showMessage("Calculating median filter pipeline... done!");
    QApplication::processEvents();
}
Beispiel #5
0
//vector field
void SolutionDialog::on_pushButton_2_clicked()
{
    if(ui->cob_x->currentIndex()==-1&&ui->cob_y->currentIndex()==-1&&ui->cob_z->currentIndex()==-1)
    {
        return;
    }
    qDebug()<<ui->cob_x->currentText()<<ui->cob_y->currentText();
        int dim = CoreDB->bases[baseindex].celldim;
         int coorddim = 0;
        if(CoreDB->bases[baseindex].zones[zoneindex].type == 2){
            coorddim = CoreDB->bases[baseindex].zones[zoneindex].dim[0]*CoreDB->bases[baseindex].zones[zoneindex].dim[1]*CoreDB->bases[baseindex].zones[zoneindex].dim[2];
        }else
        {
            coorddim = CoreDB->bases[baseindex].zones[zoneindex].dim[0];
        }
        vtkSmartPointer<vtkPoints> points =
                vtkSmartPointer<vtkPoints>::New();
        vtkSmartPointer<vtkDoubleArray> pointDataArray =
            vtkSmartPointer<vtkDoubleArray>::New();
          pointDataArray->Initialize();

        if(dim==2){
            sol_x = ui->cob_x->currentIndex();
            sol_y = ui->cob_y->currentIndex();
            int count = 0;
            if(sol_x != -1)
                count++;
            if(sol_y != -1)
                count++;
            if(count == 1){
               if(sol_x==-1){
                   sol_x = sol_y;
               }
            }
             pointDataArray->SetNumberOfComponents(count);
              for(int i=0;i<coorddim;i++)
              {
                  double x =CoreDB->bases[baseindex].zones[zoneindex].verts[i].x;
                  double y =CoreDB->bases[baseindex].zones[zoneindex].verts[i].y;
                  double xy[2];
                  xy[0] = x;
                  xy[1] = y;
                  points->InsertNextPoint(xy);
                  if(count == 1)
                  {
                     pointDataArray->InsertNextValue(CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_x].data[i]);
                  }else if(count == 2)
                  {
                     pointDataArray->InsertNextTuple2(CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_x].data[i],CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_y].data[i]);
                  }else{
                      return ;
                  }
              }
              //set salars



        }else if(dim==3)
        {
            sol_x = ui->cob_x->currentIndex();
            sol_y = ui->cob_y->currentIndex();
            sol_z = ui->cob_z->currentIndex();
            int count = 0;
            if(sol_x != -1)
                count++;
            if(sol_y != -1)
                count++;
            if(sol_z != -1)
                count++;

            pointDataArray->SetNumberOfComponents(count);
            for(int i=0;i<coorddim;i++)
            {
                double x =CoreDB->bases[baseindex].zones[zoneindex].verts[i].x;
                double y =CoreDB->bases[baseindex].zones[zoneindex].verts[i].y;
                double z =CoreDB->bases[baseindex].zones[zoneindex].verts[i].z;
                points->InsertNextPoint(x,y,z);

                if(count == 1)
                {
                   pointDataArray->InsertNextValue(CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_x].data[i]);
                }else if(count == 2)
                {
                   pointDataArray->InsertNextTuple2(CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_x].data[i],CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_y].data[i]);
                }else if(count == 3)
                {
                    pointDataArray->InsertNextTuple3(CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_x].data[i],CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_y].data[i],CoreDB->bases[baseindex].zones[zoneindex].sols[sol_index].flds[sol_z].data[i]);

                }else{
                    return ;
                }
            }

        }

       vtkSmartPointer<vtkPolyVertex> polyvertex = vtkSmartPointer<vtkPolyVertex>::New();
        polyvertex->GetPointIds()->SetNumberOfIds(coorddim);
        int i=0;
        for(i=0;i<coorddim;i++)
        {
           polyvertex->GetPointIds()->SetId(i,i);
        }
        vtkSmartPointer<vtkUnstructuredGrid> grid = vtkSmartPointer<vtkUnstructuredGrid>::New();

        grid->SetPoints(points);
//        grid->InsertNextCell(polyvertex->GetCellType(),
//                  polyvertex->GetPointIds());

       grid->GetPointData()->SetScalars(pointDataArray);
   //grid->GetPointData()->SetVectors(pointDataArray);
   double range[2];

   grid->GetScalarRange(range);
  int numPoints    = grid->GetNumberOfPoints();
     VTK_NEW(vtkLookupTable,lookUpTable);
     lookUpTable->SetRampToLinear();
     lookUpTable->SetNumberOfColors( 256 );
     lookUpTable->SetHueRange(0.667,0.0);
     lookUpTable->SetRange(range);
     lookUpTable->Build();
   vtkSmartPointer<vtkArrowSource> arrowSource = vtkSmartPointer<vtkArrowSource>::New();
   arrowSource->Update();
   VTK_NEW(vtkScalarBarActor, colorbar);
   colorbar->SetTitle("color");
   vtkSmartPointer<vtkTextProperty> prop = colorbar->GetLabelTextProperty ();
     prop->SetFontSize (4);
   colorbar->SetTitleTextProperty(prop);
   colorbar->SetOrientationToVertical();
   colorbar->SetPosition(0.8,0.1);
   colorbar->SetPosition2(0.9,0.9);
   colorbar->SetWidth(0.2);
   colorbar->SetNumberOfLabels(6);
   colorbar->SetLookupTable(lookUpTable);
   if(dim == 2){

//          VTK_NEW(vtkLookupTable,lut);

//          lut->SetNumberOfTableValues(numPoints);
//          std::vector<double> norm;
//          double min(std::numeric_limits<double>::max()), max(0);

//          for(int i=0;i<numPoints;i++)
//          {
//            // Color coding with the eigenvector
//            double vect[3];
//            data->GetPointData()->GetVectors()->GetTuple(i,vect);
//            norm.push_back(vtkMath::Norm(vect));
//            if(norm[i] < min)
//                min = norm[i];

//            if(norm[i] > max)
//                max = norm[i];
//          }

//          for(int i=0;i<numPoints;i++)
//          {


//            double hue =   (2.0/3.0)/(min-max) * norm[i] + (2 * max / 3)/(max-min);

//            double hsv[3] = {hue, 1, 1};
//            double rgb[3];
//            vtkMath::HSVToRGB(hsv, rgb);

//            lut->SetTableValue(i, rgb[0], rgb[1], rgb[2]);
//            this->ValueArray->SetTuple1(i, (unsigned int)i);
//          }

//          data->GetPointData()->SetScalars( this->ValueArray );

//          this->Glyph->SetColorModeToColorByScalar();

//          this->Glyph->Modified();

//          this->Mapper->SetLookupTable(lut);
//          this->Mapper->SetScalarRange(0, numPoints);









       vtkSmartPointer<vtkDelaunay2D> delaunay
           = vtkSmartPointer<vtkDelaunay2D>::New();
        delaunay->SetTolerance(0.00001);
        delaunay->SetInputData(grid);

        delaunay->Update();
         qDebug()<<range[0]<<range[1];
       vtkSmartPointer<vtkGlyph2D> glyphFilter = vtkSmartPointer<vtkGlyph2D>::New();
       glyphFilter->SetSourceConnection(arrowSource->GetOutputPort());
       glyphFilter->OrientOn();
       glyphFilter->SetVectorModeToUseVector();
      // glyphFilter->SetScaleModeToScaleByScalar();
        //  glyphFilter->SetColorModeToColorByScalar();
       glyphFilter->ScalingOn();
      glyphFilter->SetVectorModeToUseVector();
      glyphFilter->SetScaleModeToScaleByVector();
       glyphFilter->SetScaleFactor(0.20);
       glyphFilter->SetInputData(grid);
       glyphFilter->SetVectorModeToUseNormal();
       glyphFilter->SetScaleModeToDataScalingOff();
       glyphFilter->GeneratePointIdsOn();
      //glyphFilter->SetInputConnection(delaunay->GetOutputPort());
       //glyphFilter->SetInputData(delaunay->GetOutput());
       glyphFilter->Update();
       vtkSmartPointer<vtkPolyDataMapper> vectorMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
       vectorMapper->SetInputConnection(glyphFilter->GetOutputPort());
       vectorMapper->SetLookupTable(lookUpTable);
       vectorMapper->SetScalarRange(range);
       vectorMapper->SetScalarModeToUsePointData();
        vectorMapper->SetColorModeToMapScalars();
       vectorMapper->SetScalarVisibility(1);
       vectorMapper->UseLookupTableScalarRangeOn();

       vectorMapper->Update();

       vtkSmartPointer<vtkActor> vectorActor = vtkSmartPointer<vtkActor>::New();
       vectorActor->SetMapper(vectorMapper);
       ren->RemoveAllViewProps();
       ren->AddViewProp(vectorActor);
       ren->AddActor(colorbar);
       ren->ResetCamera();
       vtkWidget->update();
       ui->verticalLayout->update();

   }else{
       vtkSmartPointer<vtkGlyph3D> glyphFilter = vtkSmartPointer<vtkGlyph3D>::New();
       glyphFilter->SetSourceConnection(arrowSource->GetOutputPort());
       glyphFilter->OrientOn();
       glyphFilter->SetVectorModeToUseVector();
        glyphFilter->SetScaleModeToScaleByScalar();
        glyphFilter->SetColorModeToColorByScalar();
       glyphFilter->ScalingOn();
       glyphFilter->SetVectorModeToUseVector();
       glyphFilter->SetScaleModeToScaleByVector();
       glyphFilter->SetScaleFactor(0.50);
       glyphFilter->SetInputData(grid);

       glyphFilter->Update();
       vtkSmartPointer<vtkPolyDataMapper> vectorMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
       vectorMapper->SetInputConnection(glyphFilter->GetOutputPort());
       vtkSmartPointer<vtkActor> vectorActor = vtkSmartPointer<vtkActor>::New();
       vectorActor->SetMapper(vectorMapper);
       ren->RemoveAllViewProps();
       ren->AddViewProp(vectorActor);
       ren->ResetCamera();
       vtkWidget->update();
       ui->verticalLayout->update();
   }









return ;

}