[vtkusers] vtkStringArray problem

mbcx9rb9 richard.j.brown at live.co.uk
Wed Dec 3 07:29:48 EST 2014


Cory,

It is written in Qt but the first 4 lines of code create a list of DICOM
filenames. The part in the for loop is the relevant bit, when I try to write
in entry by entry into the vtkStringArray. I could just as easily comment
out the lines:

filenames->SetNumberOfValues(list.size());
filenames->SetValue(i,temp.c_str());

and uncomment the line:

filenames->InsertNextValue(temp);

however neither work. I have tried various combinations of insert temp as a
vtkStdString etc. but to no avail.

Cheers,
Rich


void MainWindow::listFiles(QString path)

{
    // set path to user chosen folder
    QDir dir = QDir(path);

    // set filter to only search for dicom files
    QStringList filters;
    filters << "*.dcm";
    dir.setNameFilters(filters);

    // Create list of all *.dcm filenames
    QStringList list = dir.entryList();

    if (list.size() == 0) { QMessageToScreen("Error. No DICOM files found in
this directory"); }
    else
    {
        // if there exist DICOM files in directory, create vector containing
them all
        vtkSmartPointer<vtkStringArray> filenames =
vtkSmartPointer<vtkStringArray>::New();
        filenames->SetNumberOfValues(list.size());
        filenames->SetName("List_of_Filenames");
        for (int i=0; i<list.size(); i++)
        {
            std::string temp = dir.absolutePath().toStdString() +
"/" + list.at(i).toStdString();
            std::cout <<temp.c_str()<<std::endl;

            //to assign data use setnumberofvalues and setvalue or
insertnextvalue
            filenames->SetValue(i,temp.c_str());
            
            //filenames->InsertNextValue(temp);
        }

        QMessageToScreen(QString::number(filenames->GetNumberOfValues()));

        // vktDICOMSorter is used to find out how many series exist in a
directory
        //vtkSmartPointer<vtkDICOMSorter> sorter =
vtkSmartPointer<vtkDICOMSorter>::New();
        //sorter->SetInputFileNames(filenames);
        //sorter->Update();
    }
}



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkStringArray-problem-tp5729638p5729646.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list